sarvekshayr commented on code in PR #8248:
URL: https://github.com/apache/ozone/pull/8248#discussion_r2053452511
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/ReplicasVerify.java:
##########
@@ -88,41 +109,122 @@ void findCandidateKeys(OzoneClient ozoneClient,
OzoneAddress address) throws IOE
String volumeName = address.getVolumeName();
String bucketName = address.getBucketName();
String keyName = address.getKeyName();
+
+ ObjectNode root = JsonUtils.createObjectNode(null);
+ ArrayNode keysArray = root.putArray("keys");
+
if (!keyName.isEmpty()) {
- OzoneKeyDetails keyDetails =
ozoneClient.getProxy().getKeyDetails(volumeName, bucketName, keyName);
- processKey(keyDetails);
+ OmKeyInfo keyInfo = ((RpcClient)
ozoneClient.getProxy()).getKeyInfo(volumeName, bucketName, keyName, false);
+ processKey(ozoneClient, keyInfo, keysArray);
} else if (!bucketName.isEmpty()) {
OzoneVolume volume = objectStore.getVolume(volumeName);
OzoneBucket bucket = volume.getBucket(bucketName);
- checkBucket(bucket);
+ checkBucket(ozoneClient, bucket, keysArray);
} else if (!volumeName.isEmpty()) {
OzoneVolume volume = objectStore.getVolume(volumeName);
- checkVolume(volume);
+ checkVolume(ozoneClient, volume, keysArray);
} else {
for (Iterator<? extends OzoneVolume> it = objectStore.listVolumes(null);
it.hasNext();) {
- checkVolume(it.next());
+ checkVolume(ozoneClient, it.next(), keysArray);
}
}
+
+ System.out.println(JsonUtils.toJsonStringWithDefaultPrettyPrinter(root));
}
- void checkVolume(OzoneVolume volume) throws IOException {
+ void checkVolume(OzoneClient ozoneClient, OzoneVolume volume, ArrayNode
keysArray) throws IOException {
for (Iterator<? extends OzoneBucket> it = volume.listBuckets(null);
it.hasNext();) {
OzoneBucket bucket = it.next();
- checkBucket(bucket);
+ checkBucket(ozoneClient, bucket, keysArray);
}
}
- void checkBucket(OzoneBucket bucket) throws IOException {
+ void checkBucket(OzoneClient ozoneClient, OzoneBucket bucket, ArrayNode
keysArray) throws IOException {
for (Iterator<? extends OzoneKey> it = bucket.listKeys(null);
it.hasNext();) {
OzoneKey key = it.next();
// TODO: Remove this check once HDDS-12094 is fixed
if (!key.getName().endsWith("/")) {
- processKey(bucket.getKey(key.getName()));
+ OmKeyInfo keyInfo = ((RpcClient) ozoneClient.getProxy()).getKeyInfo(
+ bucket.getVolumeName(), bucket.getName(), key.getName(), false);
+ processKey(ozoneClient, keyInfo, keysArray);
}
}
}
- void processKey(OzoneKeyDetails keyDetails) {
- replicaVerifiers.forEach(verifier -> verifier.verifyKey(keyDetails));
+ void processKey(OzoneClient ozoneClient, OmKeyInfo keyInfo, ArrayNode
keysArray) {
+ String volumeName = keyInfo.getVolumeName();
+ String bucketName = keyInfo.getBucketName();
+ String keyName = keyInfo.getKeyName();
+
+ ObjectNode keyNode = JsonUtils.createObjectNode(null);
+ keyNode.put("volumeName", volumeName);
+ keyNode.put("bucketName", bucketName);
+ keyNode.put("name", keyName);
+
+ ArrayNode blocksArray = keyNode.putArray("blocks");
+ boolean keyPass = true;
+
+ for (OmKeyLocationInfoGroup keyLocationInfoGroup :
keyInfo.getKeyLocationVersions()) {
+ for (OmKeyLocationInfo keyLocation :
keyLocationInfoGroup.getLocationList()) {
+ long containerID = keyLocation.getContainerID();
+ long localID = keyLocation.getLocalID();
+
+ ObjectNode blockNode = JsonUtils.createObjectNode(null);
Review Comment:
Thanks for the suggestion!
We intentionally create a separate `ObjectNode keyNode =
JsonUtils.createObjectNode(null);` so we can determine the result of the
replica verification before deciding whether or not to include the key in the
final output.
The top level root node represents the overall result and contains the
"keys" array. Each `keyNode` is constructed independently so we can compute the
pass status for that key first. If `--all-results` is disabled and the key has
passed, we skip adding it to the array. This filtering wouldn’t be possible if
we added the key directly via `addObject()` at the start.
Rest of the nodes/arrays are now created and added using either
`putObject/addObject/putArray` calls.
--
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]