errose28 commented on code in PR #8146:
URL: https://github.com/apache/ozone/pull/8146#discussion_r2036134021


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/chunk/ChunkKeyHandler.java:
##########
@@ -71,9 +74,11 @@ protected void execute(OzoneClient client, OzoneAddress 
address)
       String volumeName = address.getVolumeName();
       String bucketName = address.getBucketName();
       String keyName = address.getKeyName();
-      List<ContainerProtos.ChunkInfo> tempchunks;
-      List<ChunkDetails> chunkDetailsList = new ArrayList<>();
-      HashSet<String> chunkPaths = new HashSet<>();
+
+      result.put("volumeName", volumeName);
+      result.put("bucketName", bucketName);
+      result.put("name", keyName);
+

Review Comment:
   On line 88 (old code) `getLatestVersionLocation` can return null if the key 
has no replicas. We should update this tool to handle that.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/chunk/ChunkKeyHandler.java:
##########
@@ -71,9 +74,11 @@ protected void execute(OzoneClient client, OzoneAddress 
address)
       String volumeName = address.getVolumeName();
       String bucketName = address.getBucketName();
       String keyName = address.getKeyName();
-      List<ContainerProtos.ChunkInfo> tempchunks;
-      List<ChunkDetails> chunkDetailsList = new ArrayList<>();
-      HashSet<String> chunkPaths = new HashSet<>();
+
+      result.put("volumeName", volumeName);
+      result.put("bucketName", bucketName);
+      result.put("name", keyName);
+

Review Comment:
   Line 91 should print to stderr so it is visible even if the command was 
piped to jq. Let's also replace the use of `LOG.error` with printing to stderr 
and specify which node and block failed.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/chunk/ChunkKeyHandler.java:
##########
@@ -123,51 +119,64 @@ protected void execute(OzoneClient client, OzoneAddress 
address)
                   keyLocation.getContainerID(), pipeline);
           ArrayNode responseFromAllNodes = JsonUtils.createArrayNode();
           for (Map.Entry<DatanodeDetails, 
ContainerProtos.GetBlockResponseProto> entry : responses.entrySet()) {
-            chunkPaths.clear();
             ObjectNode jsonObj = JsonUtils.createObjectNode(null);
             if (entry.getValue() == null) {
-              LOG.error("Cant execute getBlock on this node");
+              LOG.error("Can't execute getBlock on this node");
               continue;
             }
-            tempchunks = entry.getValue().getBlockData().getChunksList();
-            ContainerProtos.ContainerDataProto containerData =
-                readContainerResponses.get(entry.getKey()).getContainerData();
-            for (ContainerProtos.ChunkInfo chunkInfo : tempchunks) {
-              String fileName = containerLayoutVersion.getChunkFile(new File(
+            ContainerProtos.ChunkInfo chunks = null;
+            String fileName = "";
+            if (entry.getValue().getBlockData().getChunksCount() > 0) {
+              chunks = entry.getValue().getBlockData().getChunks(0);
+              ContainerProtos.ContainerDataProto containerData =
+                  
readContainerResponses.get(entry.getKey()).getContainerData();
+              fileName = containerLayoutVersion.getChunkFile(new File(
                       getChunkLocationPath(containerData.getContainerPath())),
                   keyLocation.getBlockID(),
-                  chunkInfo.getChunkName()).toString();
-              chunkPaths.add(fileName);
-              ChunkDetails chunkDetails = new ChunkDetails();
-              chunkDetails.setChunkName(fileName);
-              chunkDetails.setChunkOffset(chunkInfo.getOffset());
-              chunkDetailsList.add(chunkDetails);
+                  chunks.getChunkName()).toString();
             }
-            containerChunkInfoVerbose.setContainerPath(containerData
-                .getContainerPath());
-            containerChunkInfoVerbose.setPipeline(keyPipeline);
-            containerChunkInfoVerbose.setChunkInfos(chunkDetailsList);
-            containerChunkInfo.setFiles(chunkPaths);
-            containerChunkInfo.setPipelineID(keyPipeline.getId().getId());
-            if (isECKey) {
-              ChunkType blockChunksType =
-                  isECParityBlock(keyPipeline, entry.getKey()) ?
-                      ChunkType.PARITY : ChunkType.DATA;
-              containerChunkInfoVerbose.setChunkType(blockChunksType);
-              containerChunkInfo.setChunkType(blockChunksType);
+
+            ObjectNode dnObj = JsonUtils.createObjectNode(null);
+            dnObj.put("hostname", entry.getKey().getHostName());
+            dnObj.put("ip", entry.getKey().getIpAddress());
+            dnObj.put("uuid", entry.getKey().getUuidString());
+            jsonObj.set("datanode", dnObj);
+
+            jsonObj.put("file", fileName);
+
+            ObjectMapper objectMapper = new ObjectMapper();
+            JsonNode blockDataNode = 
objectMapper.readTree(JsonFormat.printer().print(entry.getValue().getBlockData()));

Review Comment:
   This is going to create an intermediate json object, which we then just 
extract values from to put in our final json object. We should just extract 
values from the proto and put them in our json objects directly without this 
step.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/chunk/ChunkKeyHandler.java:
##########
@@ -123,51 +119,64 @@ protected void execute(OzoneClient client, OzoneAddress 
address)
                   keyLocation.getContainerID(), pipeline);
           ArrayNode responseFromAllNodes = JsonUtils.createArrayNode();
           for (Map.Entry<DatanodeDetails, 
ContainerProtos.GetBlockResponseProto> entry : responses.entrySet()) {
-            chunkPaths.clear();
             ObjectNode jsonObj = JsonUtils.createObjectNode(null);
             if (entry.getValue() == null) {
-              LOG.error("Cant execute getBlock on this node");
+              LOG.error("Can't execute getBlock on this node");
               continue;
             }
-            tempchunks = entry.getValue().getBlockData().getChunksList();
-            ContainerProtos.ContainerDataProto containerData =
-                readContainerResponses.get(entry.getKey()).getContainerData();
-            for (ContainerProtos.ChunkInfo chunkInfo : tempchunks) {
-              String fileName = containerLayoutVersion.getChunkFile(new File(
+            ContainerProtos.ChunkInfo chunks = null;
+            String fileName = "";
+            if (entry.getValue().getBlockData().getChunksCount() > 0) {
+              chunks = entry.getValue().getBlockData().getChunks(0);
+              ContainerProtos.ContainerDataProto containerData =
+                  
readContainerResponses.get(entry.getKey()).getContainerData();
+              fileName = containerLayoutVersion.getChunkFile(new File(
                       getChunkLocationPath(containerData.getContainerPath())),
                   keyLocation.getBlockID(),
-                  chunkInfo.getChunkName()).toString();
-              chunkPaths.add(fileName);
-              ChunkDetails chunkDetails = new ChunkDetails();
-              chunkDetails.setChunkName(fileName);
-              chunkDetails.setChunkOffset(chunkInfo.getOffset());
-              chunkDetailsList.add(chunkDetails);
+                  chunks.getChunkName()).toString();
             }
-            containerChunkInfoVerbose.setContainerPath(containerData
-                .getContainerPath());
-            containerChunkInfoVerbose.setPipeline(keyPipeline);
-            containerChunkInfoVerbose.setChunkInfos(chunkDetailsList);
-            containerChunkInfo.setFiles(chunkPaths);
-            containerChunkInfo.setPipelineID(keyPipeline.getId().getId());
-            if (isECKey) {
-              ChunkType blockChunksType =
-                  isECParityBlock(keyPipeline, entry.getKey()) ?
-                      ChunkType.PARITY : ChunkType.DATA;
-              containerChunkInfoVerbose.setChunkType(blockChunksType);
-              containerChunkInfo.setChunkType(blockChunksType);
+
+            ObjectNode dnObj = JsonUtils.createObjectNode(null);

Review Comment:
   For adding objects or arrays to other json objects, we should add them to 
the return value of `ObjectNode#putArray(String)` or `ObjectNode#putObject` 
respectively.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/chunk/ChunkKeyHandler.java:
##########
@@ -123,51 +119,64 @@ protected void execute(OzoneClient client, OzoneAddress 
address)
                   keyLocation.getContainerID(), pipeline);
           ArrayNode responseFromAllNodes = JsonUtils.createArrayNode();
           for (Map.Entry<DatanodeDetails, 
ContainerProtos.GetBlockResponseProto> entry : responses.entrySet()) {
-            chunkPaths.clear();
             ObjectNode jsonObj = JsonUtils.createObjectNode(null);
             if (entry.getValue() == null) {
-              LOG.error("Cant execute getBlock on this node");
+              LOG.error("Can't execute getBlock on this node");
               continue;
             }
-            tempchunks = entry.getValue().getBlockData().getChunksList();
-            ContainerProtos.ContainerDataProto containerData =
-                readContainerResponses.get(entry.getKey()).getContainerData();
-            for (ContainerProtos.ChunkInfo chunkInfo : tempchunks) {
-              String fileName = containerLayoutVersion.getChunkFile(new File(
+            ContainerProtos.ChunkInfo chunks = null;
+            String fileName = "";
+            if (entry.getValue().getBlockData().getChunksCount() > 0) {
+              chunks = entry.getValue().getBlockData().getChunks(0);
+              ContainerProtos.ContainerDataProto containerData =
+                  
readContainerResponses.get(entry.getKey()).getContainerData();
+              fileName = containerLayoutVersion.getChunkFile(new File(
                       getChunkLocationPath(containerData.getContainerPath())),
                   keyLocation.getBlockID(),
-                  chunkInfo.getChunkName()).toString();
-              chunkPaths.add(fileName);
-              ChunkDetails chunkDetails = new ChunkDetails();
-              chunkDetails.setChunkName(fileName);
-              chunkDetails.setChunkOffset(chunkInfo.getOffset());
-              chunkDetailsList.add(chunkDetails);
+                  chunks.getChunkName()).toString();
             }
-            containerChunkInfoVerbose.setContainerPath(containerData
-                .getContainerPath());
-            containerChunkInfoVerbose.setPipeline(keyPipeline);
-            containerChunkInfoVerbose.setChunkInfos(chunkDetailsList);
-            containerChunkInfo.setFiles(chunkPaths);
-            containerChunkInfo.setPipelineID(keyPipeline.getId().getId());
-            if (isECKey) {
-              ChunkType blockChunksType =
-                  isECParityBlock(keyPipeline, entry.getKey()) ?
-                      ChunkType.PARITY : ChunkType.DATA;
-              containerChunkInfoVerbose.setChunkType(blockChunksType);
-              containerChunkInfo.setChunkType(blockChunksType);
+
+            ObjectNode dnObj = JsonUtils.createObjectNode(null);
+            dnObj.put("hostname", entry.getKey().getHostName());
+            dnObj.put("ip", entry.getKey().getIpAddress());
+            dnObj.put("uuid", entry.getKey().getUuidString());
+            jsonObj.set("datanode", dnObj);
+
+            jsonObj.put("file", fileName);
+
+            ObjectMapper objectMapper = new ObjectMapper();
+            JsonNode blockDataNode = 
objectMapper.readTree(JsonFormat.printer().print(entry.getValue().getBlockData()));
+
+            if (entry.getValue().hasBlockData()) {

Review Comment:
   We should save the key and value of the entry by name at the top of the loop 
since they are referenced a lot. Also the block data was already used farther 
up, so if we need to check its existence that should happen towards the top of 
the loop as well.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/replicas/chunk/ChunkKeyHandler.java:
##########
@@ -177,12 +186,17 @@ protected void execute(OzoneClient client, OzoneAddress 
address)
           xceiverClientManager.releaseClientForReadData(xceiverClient, false);
         }
       }
-      result.set("KeyLocations", responseArrayList);
+      result.set("keyLocations", responseArrayList);
       String prettyJson = 
JsonUtils.toJsonStringWithDefaultPrettyPrinter(result);
       System.out.println(prettyJson);
     }
   }
 
+  private String convertBase64ToHex(String base64Checksum) {

Review Comment:
   We should `StringUtils#byteToHexString` directly instead of making a new 
method.



-- 
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]

Reply via email to