-
Notifications
You must be signed in to change notification settings - Fork 621
HDDS-12495. Add metadata flag to check block existence in ozone debug verify replicas #8079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1613f19
HDDS-12495. Add metadata flag to check block existence in ozone debug…
sarvekshayr 11762a7
Check if all replicas have the block and print the output
sarvekshayr 52b5d02
Include blockId in the output
sarvekshayr dd69e33
Merge branch 'master' into HDDS-12495
sarvekshayr 8fbb9f7
Added integration and acceptance tests
sarvekshayr abbbd03
Fixed a bug
sarvekshayr dd030e5
Renamed the verifier and used Jackson to read and parse output
sarvekshayr 44949c6
Correct acceptance test command
sarvekshayr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
...egration-test/src/test/java/org/apache/hadoop/ozone/debug/replicas/TestMetadataCheck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
| } | ||
|
|
||
| @Order(2) | ||
| @Test | ||
| void testMissingReplicas() throws IOException { | ||
| OzoneKeyDetails keyDetails = client.getProxy().getKeyDetails(VOLUME_NAME, BUCKET_NAME, KEY_NAME); | ||
|
|
||
| List<OmKeyLocationInfo> keyLocations = lookupKey(cluster); | ||
| assertThat(keyLocations).isNotEmpty(); | ||
|
|
||
| OmKeyLocationInfo keyLocation = keyLocations.get(0); | ||
| BlockID blockID = keyLocation.getBlockID(); | ||
| // Iterate over Datanodes | ||
| for (HddsDatanodeService datanode : cluster.getHddsDatanodes()) { | ||
| ContainerSet dnContainerSet = datanode.getDatanodeStateMachine().getContainer().getContainerSet(); | ||
|
|
||
| // Retrieve the container for the block | ||
| KeyValueContainer container = (KeyValueContainer) dnContainerSet.getContainer(blockID.getContainerID()); | ||
| KeyValueContainerData containerData = container.getContainerData(); | ||
|
|
||
| try (DBHandle db = BlockUtils.getDB(containerData, conf)) { | ||
| Table<String, BlockData> blockDataTable = db.getStore().getBlockDataTable(); | ||
|
|
||
| String blockKey = containerData.getBlockKey(blockID.getLocalID()); | ||
|
|
||
| // Ensure the block exists before deletion | ||
| assertNotNull(blockDataTable.get(blockKey)); | ||
|
|
||
| // Delete the block from RocksDB | ||
| blockDataTable.delete(blockKey); | ||
|
|
||
| // Verify deletion | ||
| assertNull(blockDataTable.get(blockKey)); | ||
| } | ||
| } | ||
|
|
||
| metadataCheck.verifyKey(keyDetails); | ||
| String cliOutput = OUT.toString(); | ||
|
|
||
| assertThat(cliOutput).contains("\"status\":\"MISSING_REPLICAS\""); | ||
| assertThat(cliOutput).contains("\"pass\":false"); | ||
| } | ||
|
|
||
| private static List<OmKeyLocationInfo> lookupKey(MiniOzoneCluster ozoneCluster) | ||
| throws IOException { | ||
| OmKeyArgs keyArgs = new OmKeyArgs.Builder() | ||
| .setVolumeName(VOLUME_NAME) | ||
| .setBucketName(BUCKET_NAME) | ||
| .setKeyName(KEY_NAME) | ||
| .build(); | ||
| OmKeyInfo keyInfo = ozoneCluster.getOzoneManager().lookupKey(keyArgs); | ||
|
|
||
| OmKeyLocationInfoGroup locations = keyInfo.getLatestVersionLocations(); | ||
| assertNotNull(locations); | ||
| return locations.getLocationList(); | ||
| } | ||
|
|
||
| private static void writeKey(String keyName) throws IOException { | ||
| try (OzoneClient client = OzoneClientFactory.getRpcClient(conf)) { | ||
| TestDataUtil.createVolumeAndBucket(client, VOLUME_NAME, BUCKET_NAME); | ||
| TestDataUtil.createKey( | ||
| client.getObjectStore().getVolume(VOLUME_NAME).getBucket(BUCKET_NAME), | ||
| keyName, "test".getBytes(StandardCharsets.UTF_8)); | ||
| } | ||
| } | ||
|
|
||
| } | ||
156 changes: 156 additions & 0 deletions
156
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/MetadataCheck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
|
sarvekshayr marked this conversation as resolved.
|
||
| 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); | ||
|
sarvekshayr marked this conversation as resolved.
|
||
| return; | ||
| } | ||
|
|
||
| String blockId = null; | ||
| boolean allReplicasHaveBlock = true; | ||
| for (OmKeyLocationInfo keyLocation : keyLocations) { | ||
| Pipeline keyPipeline = keyLocation.getPipeline(); | ||
| boolean isECKey = keyPipeline.getReplicationConfig().getReplicationType() == HddsProtos.ReplicationType.EC; | ||
|
|
||
| Pipeline pipeline = isECKey ? keyPipeline : | ||
| Pipeline.newBuilder(keyPipeline).setReplicationConfig(StandaloneReplicationConfig.getInstance(ONE)).build(); | ||
|
|
||
| XceiverClientSpi xceiverClient = xceiverClientManager.acquireClientForReadData(pipeline); | ||
| try { | ||
| Map<DatanodeDetails, ContainerProtos.GetBlockResponseProto> responses = | ||
| ContainerProtocolCalls.getBlockFromAllNodes(xceiverClient, | ||
| keyLocation.getBlockID().getDatanodeBlockIDProtobuf(), keyLocation.getToken()); | ||
|
|
||
| blockId = keyLocation.getBlockID().toString(); | ||
| int totalExpectedReplicas = responses.size(); | ||
| int availableReplicas = 0; | ||
|
|
||
| for (Map.Entry<DatanodeDetails, ContainerProtos.GetBlockResponseProto> entry : responses.entrySet()) { | ||
| if (entry.getValue() != null && entry.getValue().hasBlockData()) { | ||
| availableReplicas++; | ||
| } | ||
| } | ||
|
|
||
| if (availableReplicas < totalExpectedReplicas || totalExpectedReplicas == 0) { | ||
| allReplicasHaveBlock = false; | ||
| } | ||
|
|
||
| } finally { | ||
| xceiverClientManager.releaseClientForReadData(xceiverClient, false); | ||
| } | ||
| } | ||
|
|
||
| if (allReplicasHaveBlock) { | ||
| printJsonResult(keyDetails, "BLOCK_EXISTS", blockId, true, result); | ||
| } else { | ||
| printJsonResult(keyDetails, "MISSING_REPLICAS", blockId, false, result); | ||
| } | ||
|
|
||
| } catch (IOException | InterruptedException e) { | ||
| log.error("Error checking block existence for key {}: {}", keyDetails.getName(), e.getMessage()); | ||
| printJsonError(keyDetails, e.getMessage(), false, result); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to print JSON results. | ||
| */ | ||
| private void printJsonResult(OzoneKeyDetails keyParts, String status, String blockId, | ||
| boolean pass, ObjectNode result) { | ||
| result.put("key", keyParts.getVolumeName() + "/" + keyParts.getBucketName() + "/" + keyParts.getName()); | ||
| result.put("blockID", blockId); | ||
| result.put("status", status); | ||
| result.put("pass", pass); | ||
|
|
||
| printWriter.println(result); | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to print JSON error messages. | ||
| */ | ||
| private void printJsonError(OzoneKeyDetails keyParts, String errorMessage, boolean pass, ObjectNode result) { | ||
| result.put("key", keyParts.getVolumeName() + "/" + keyParts.getBucketName() + "/" + keyParts.getName()); | ||
| result.put("status", "ERROR"); | ||
| result.put("message", errorMessage); | ||
| result.put("pass", pass); | ||
|
|
||
| printWriter.println(result); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.