errose28 commented on code in PR #8079: URL: https://github.com/apache/ozone/pull/8079#discussion_r2026133115
########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/MetadataCheck.java: ########## @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.ozone.debug.replicas; + +import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; +import java.util.Map; +import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.XceiverClientManager; +import org.apache.hadoop.hdds.scm.XceiverClientSpi; +import org.apache.hadoop.hdds.scm.cli.ContainerOperationClient; +import org.apache.hadoop.hdds.scm.pipeline.Pipeline; +import org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls; +import org.apache.hadoop.hdds.server.JsonUtils; +import org.apache.hadoop.ozone.client.OzoneClient; +import org.apache.hadoop.ozone.client.OzoneKeyDetails; +import org.apache.hadoop.ozone.om.helpers.OmKeyArgs; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; +import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol; +import org.slf4j.Logger; + +/** + * Checks block existence using GetBlock calls to the Datanodes. + */ +public class MetadataCheck implements ReplicaVerifier { + + private OzoneClient client; + private Logger log; + private PrintWriter printWriter; + private OzoneConfiguration conf; + + public MetadataCheck(OzoneClient client, Logger log, PrintWriter printWriter, OzoneConfiguration conf) { + this.client = client; + this.log = log; + this.printWriter = printWriter; + this.conf = conf; + } + + @Override + public void verifyKey(OzoneKeyDetails keyDetails) { + ObjectNode result = JsonUtils.createObjectNode(null); + + try (ContainerOperationClient containerOperationClient = new ContainerOperationClient(conf); + XceiverClientManager xceiverClientManager = containerOperationClient.getXceiverClientManager()) { + + OzoneManagerProtocol ozoneManagerClient = client.getObjectStore().getClientProxy().getOzoneManagerClient(); + OmKeyArgs keyArgs = new OmKeyArgs.Builder() + .setVolumeName(keyDetails.getVolumeName()) + .setBucketName(keyDetails.getBucketName()) + .setKeyName(keyDetails.getName()) + .build(); + + OmKeyInfo keyInfo = ozoneManagerClient.lookupKey(keyArgs); + List<OmKeyLocationInfo> keyLocations = keyInfo.getLatestVersionLocations().getBlocksLatestVersionOnly(); + + if (keyLocations.isEmpty()) { + printJsonResult(keyDetails, "NO_BLOCKS", null, false, result); Review Comment: Does OM allow committing keys with no blocks? If so we need to distinguish the case of a key that correctly has no blocks to verify, and a key that block metadata but no block replicas. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/ReplicasVerify.java: ########## @@ -64,6 +64,11 @@ static class Verification { defaultValue = "false") private boolean doExecuteChecksums; + @CommandLine.Option(names = "--metadata", Review Comment: ```suggestion @CommandLine.Option(names = "--block-existence", ``` I'm thinking this might be a more descriptive name than the original proposal. We can rename the Verifier class too. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/MetadataCheck.java: ########## @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.ozone.debug.replicas; + +import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; +import java.util.Map; +import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.XceiverClientManager; +import org.apache.hadoop.hdds.scm.XceiverClientSpi; +import org.apache.hadoop.hdds.scm.cli.ContainerOperationClient; +import org.apache.hadoop.hdds.scm.pipeline.Pipeline; +import org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls; +import org.apache.hadoop.hdds.server.JsonUtils; +import org.apache.hadoop.ozone.client.OzoneClient; +import org.apache.hadoop.ozone.client.OzoneKeyDetails; +import org.apache.hadoop.ozone.om.helpers.OmKeyArgs; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; +import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol; +import org.slf4j.Logger; + +/** + * Checks block existence using GetBlock calls to the Datanodes. + */ +public class MetadataCheck implements ReplicaVerifier { + + private OzoneClient client; + private Logger log; + private PrintWriter printWriter; + private OzoneConfiguration conf; + + public MetadataCheck(OzoneClient client, Logger log, PrintWriter printWriter, OzoneConfiguration conf) { + this.client = client; + this.log = log; + this.printWriter = printWriter; + this.conf = conf; + } + + @Override + public void verifyKey(OzoneKeyDetails keyDetails) { + ObjectNode result = JsonUtils.createObjectNode(null); + + try (ContainerOperationClient containerOperationClient = new ContainerOperationClient(conf); + XceiverClientManager xceiverClientManager = containerOperationClient.getXceiverClientManager()) { + + OzoneManagerProtocol ozoneManagerClient = client.getObjectStore().getClientProxy().getOzoneManagerClient(); Review Comment: Eventually we probably want the clients to be initialized once for each verifier instance, not on a per-check basis. For clients that need to be released, we may need to make the `ReplicaVerifier` extend `Autocloseable` and have the main driver close all the verifiers when it is done. We can do this in a later change though, maybe as part of the json output PR where we are making everything work at a block level, so OM clients won't be needed here anymore. ########## hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/debug/replicas/TestMetadataCheck.java: ########## @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.ozone.debug.replicas; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.UUID; +import org.apache.hadoop.hdds.client.BlockID; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.utils.IOUtils; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.ozone.HddsDatanodeService; +import org.apache.hadoop.ozone.MiniOzoneCluster; +import org.apache.hadoop.ozone.TestDataUtil; +import org.apache.hadoop.ozone.client.OzoneClient; +import org.apache.hadoop.ozone.client.OzoneClientFactory; +import org.apache.hadoop.ozone.client.OzoneKeyDetails; +import org.apache.hadoop.ozone.container.common.helpers.BlockData; +import org.apache.hadoop.ozone.container.common.impl.ContainerSet; +import org.apache.hadoop.ozone.container.common.interfaces.DBHandle; +import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer; +import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData; +import org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils; +import org.apache.hadoop.ozone.om.helpers.OmKeyArgs; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class checks block existence using GetBlock calls to the Datanodes. + */ +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class TestMetadataCheck { + + private static final Logger LOG = LoggerFactory.getLogger(TestMetadataCheck.class); + private static MiniOzoneCluster cluster; + private static OzoneClient client; + private static OzoneConfiguration conf; + private static MetadataCheck metadataCheck; + private static final String VOLUME_NAME = UUID.randomUUID().toString(); + private static final String BUCKET_NAME = UUID.randomUUID().toString(); + private static final String KEY_NAME = UUID.randomUUID().toString(); + private static final StringWriter OUT = new StringWriter(); + private static PrintWriter printWriter; + + @BeforeAll + public static void setUp() throws Exception { + conf = new OzoneConfiguration(); + cluster = MiniOzoneCluster.newBuilder(conf) + .setNumDatanodes(3) + .build(); + cluster.waitForClusterToBeReady(); + client = cluster.newClient(); + + writeKey(KEY_NAME); + + printWriter = new PrintWriter(OUT); + metadataCheck = new MetadataCheck(client, LOG, printWriter, conf); + } + + @AfterEach + public void cleanUp() { + OUT.flush(); + } + + @AfterAll + public static void tearDown() { + IOUtils.closeQuietly(client, cluster); + } + + @Order(1) + @Test + void testBlockExists() throws IOException { + OzoneKeyDetails keyDetails = client.getProxy().getKeyDetails(VOLUME_NAME, BUCKET_NAME, KEY_NAME); + + metadataCheck.verifyKey(keyDetails); + String cliOutput = OUT.toString(); + + assertThat(cliOutput).contains("\"status\":\"BLOCK_EXISTS\""); + assertThat(cliOutput).contains("\"pass\":true"); Review Comment: Can we read this in with Jackson and parse it, or is that too cumbersome? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
