You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "adoroszlai (via GitHub)" <gi...@apache.org> on 2023/05/06 14:05:06 UTC

[GitHub] [ozone] adoroszlai commented on a diff in pull request #4661: HDDS-8546. Ozone debug chunkinfo command throwing GroupMismatchException after container is closed.

adoroszlai commented on code in PR #4661:
URL: https://github.com/apache/ozone/pull/4661#discussion_r1186702108


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkKeyHandler.java:
##########
@@ -71,124 +72,130 @@ public class ChunkKeyHandler extends KeyHandler implements
   private XceiverClientSpi xceiverClient;
   private OzoneManagerProtocol ozoneManagerClient;
 
+  @CommandLine.ParentCommand
+  private OzoneDebug parent;
+
   private String getChunkLocationPath(String containerLocation) {
     return containerLocation + File.separator + OzoneConsts.STORAGE_DIR_CHUNKS;
   }
 
   @Override
   protected void execute(OzoneClient client, OzoneAddress address)
           throws IOException, OzoneClientException {
-    containerOperationClient = new
-            ContainerOperationClient(createOzoneConfiguration());
-    xceiverClientManager = containerOperationClient
-            .getXceiverClientManager();
-    ozoneManagerClient = client.getObjectStore().getClientProxy()
-            .getOzoneManagerClient();
-    address.ensureKeyAddress();
-    JsonElement element;
-    JsonObject result = new JsonObject();
-    String volumeName = address.getVolumeName();
-    String bucketName = address.getBucketName();
-    String keyName = address.getKeyName();
-    List<ContainerProtos.ChunkInfo> tempchunks = null;
-    List<ChunkDetails> chunkDetailsList = new ArrayList<ChunkDetails>();
-    HashSet<String> chunkPaths = new HashSet<>();
-    OmKeyArgs keyArgs = new OmKeyArgs.Builder()
-            .setVolumeName(volumeName)
-            .setBucketName(bucketName)
-            .setKeyName(keyName)
-            .build();
-    OmKeyInfo keyInfo = ozoneManagerClient.lookupKey(keyArgs);
-    // querying  the keyLocations.The OM is queried to get containerID and
-    // localID pertaining to a given key
-    List<OmKeyLocationInfo> locationInfos = keyInfo
-            .getLatestVersionLocations().getBlocksLatestVersionOnly();
-    // for zero-sized key
-    if (locationInfos.isEmpty()) {
-      System.out.println("No Key Locations Found");
-      return;
-    }
-    ContainerLayoutVersion containerLayoutVersion = ContainerLayoutVersion
-            .getConfiguredVersion(getConf());
-    JsonArray responseArrayList = new JsonArray();
-    for (OmKeyLocationInfo keyLocation:locationInfos) {
-      ContainerChunkInfo containerChunkInfoVerbose = new ContainerChunkInfo();
-      ContainerChunkInfo containerChunkInfo = new ContainerChunkInfo();
-      long containerId = keyLocation.getContainerID();
-      chunkPaths.clear();
-      Pipeline pipeline = keyLocation.getPipeline();
-      if (pipeline.getType() != HddsProtos.ReplicationType.STAND_ALONE) {
-        pipeline = Pipeline.newBuilder(pipeline)
-            .setReplicationConfig(StandaloneReplicationConfig.getInstance(ONE))
-            .build();
-      }
-      xceiverClient = xceiverClientManager
-              .acquireClientForReadData(pipeline);
-      // Datanode is queried to get chunk information.Thus querying the
-      // OM,SCM and datanode helps us get chunk location information
-      ContainerProtos.DatanodeBlockID datanodeBlockID = keyLocation.getBlockID()
-              .getDatanodeBlockIDProtobuf();
-      // doing a getBlock on all nodes
-      HashMap<DatanodeDetails, ContainerProtos.GetBlockResponseProto>
-              responses = null;
-      try {
-        responses = ContainerProtocolCalls.getBlockFromAllNodes(
-            xceiverClient, datanodeBlockID, keyLocation.getToken());
-      } catch (InterruptedException e) {
-        LOG.error("Execution interrupted due to " + e);
-        Thread.currentThread().interrupt();
+    try {
+      containerOperationClient = new ContainerOperationClient(
+          parent.getOzoneConf());
+      xceiverClientManager = containerOperationClient.getXceiverClientManager();
+      ozoneManagerClient =
+          client.getObjectStore().getClientProxy().getOzoneManagerClient();
+      address.ensureKeyAddress();
+      JsonElement element;
+      JsonObject result = new JsonObject();
+      String volumeName = address.getVolumeName();
+      String bucketName = address.getBucketName();
+      String keyName = address.getKeyName();
+      List<ContainerProtos.ChunkInfo> tempchunks = null;
+      List<ChunkDetails> chunkDetailsList = new ArrayList<ChunkDetails>();
+      HashSet<String> chunkPaths = new HashSet<>();
+      OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName)
+          .setBucketName(bucketName).setKeyName(keyName).build();
+      OmKeyInfo keyInfo = ozoneManagerClient.lookupKey(keyArgs);
+      // querying  the keyLocations.The OM is queried to get containerID and
+      // localID pertaining to a given key
+      List<OmKeyLocationInfo> locationInfos =
+          keyInfo.getLatestVersionLocations().getBlocksLatestVersionOnly();
+      // for zero-sized key
+      if (locationInfos.isEmpty()) {
+        System.out.println("No Key Locations Found");
+        return;
       }
-      JsonArray responseFromAllNodes = new JsonArray();
-      for (Map.Entry<DatanodeDetails, ContainerProtos.GetBlockResponseProto>
-              entry: responses.entrySet()) {
-        JsonObject jsonObj = new JsonObject();
-        if (entry.getValue() == null) {
-          LOG.error("Cant execute getBlock on this node");
-          continue;
+      ContainerLayoutVersion containerLayoutVersion = ContainerLayoutVersion
+          .getConfiguredVersion(getConf());
+      JsonArray responseArrayList = new JsonArray();
+      for (OmKeyLocationInfo keyLocation : locationInfos) {
+        ContainerChunkInfo containerChunkInfoVerbose = new ContainerChunkInfo();
+        ContainerChunkInfo containerChunkInfo = new ContainerChunkInfo();
+        long containerId = keyLocation.getContainerID();
+        chunkPaths.clear();
+        Pipeline pipeline = keyLocation.getPipeline();
+        if (pipeline.getType() != HddsProtos.ReplicationType.STAND_ALONE) {
+          pipeline = Pipeline.newBuilder(pipeline)
+              .setReplicationConfig(StandaloneReplicationConfig
+                  .getInstance(ONE)).build();
         }
-        tempchunks = entry.getValue().getBlockData().getChunksList();
-        ContainerProtos.ContainerDataProto containerData =
-                containerOperationClient.readContainer(
-                        keyLocation.getContainerID(),
-                        keyLocation.getPipeline());
-        for (ContainerProtos.ChunkInfo chunkInfo : tempchunks) {
-          String fileName = containerLayoutVersion.getChunkFile(new File(
-              getChunkLocationPath(containerData.getContainerPath())),
-                  keyLocation.getBlockID(),
-                  ChunkInfo.getFromProtoBuf(chunkInfo)).toString();
-          chunkPaths.add(fileName);
-          ChunkDetails chunkDetails = new ChunkDetails();
-          chunkDetails.setChunkName(fileName);
-          chunkDetails.setChunkOffset(chunkInfo.getOffset());
-          chunkDetailsList.add(chunkDetails);
+        xceiverClient = xceiverClientManager.acquireClientForReadData(pipeline);
+        // Datanode is queried to get chunk information.Thus querying the
+        // OM,SCM and datanode helps us get chunk location information
+        ContainerProtos.DatanodeBlockID datanodeBlockID =
+            keyLocation.getBlockID().getDatanodeBlockIDProtobuf();
+        // doing a getBlock on all nodes
+        HashMap<DatanodeDetails, ContainerProtos.GetBlockResponseProto>
+            responses = null;
+        try {
+          responses = ContainerProtocolCalls.getBlockFromAllNodes(xceiverClient,
+              datanodeBlockID, keyLocation.getToken());
+        } catch (InterruptedException e) {
+          LOG.error("Execution interrupted due to " + e);
+          Thread.currentThread().interrupt();
         }
-        containerChunkInfoVerbose
-                .setContainerPath(containerData.getContainerPath());
-        containerChunkInfoVerbose.setPipeline(keyLocation.getPipeline());
-        containerChunkInfoVerbose.setChunkInfos(chunkDetailsList);
-        containerChunkInfo.setFiles(chunkPaths);
-        containerChunkInfo.setPipelineID(
-                keyLocation.getPipeline().getId().getId());
-        Gson gson = new GsonBuilder().create();
-        if (isVerbose()) {
-          element = gson.toJsonTree(containerChunkInfoVerbose);
-        } else {
-          element = gson.toJsonTree(containerChunkInfo);
+        JsonArray responseFromAllNodes = new JsonArray();
+        for (Map.Entry<DatanodeDetails, ContainerProtos.GetBlockResponseProto>
+            entry : responses.entrySet()) {
+          JsonObject jsonObj = new JsonObject();
+          if (entry.getValue() == null) {
+            LOG.error("Cant execute getBlock on this node");
+            continue;
+          }
+          tempchunks = entry.getValue().getBlockData().getChunksList();
+          ContainerProtos.ContainerDataProto containerData =
+              containerOperationClient.readContainer(keyLocation
+                  .getContainerID(), pipeline);
+          for (ContainerProtos.ChunkInfo chunkInfo : tempchunks) {
+            String fileName = containerLayoutVersion.getChunkFile(new File(
+                    getChunkLocationPath(containerData.getContainerPath())),
+                keyLocation.getBlockID(),
+                ChunkInfo.getFromProtoBuf(chunkInfo)).toString();
+            chunkPaths.add(fileName);
+            ChunkDetails chunkDetails = new ChunkDetails();
+            chunkDetails.setChunkName(fileName);
+            chunkDetails.setChunkOffset(chunkInfo.getOffset());
+            chunkDetailsList.add(chunkDetails);
+          }
+          containerChunkInfoVerbose.setContainerPath(containerData
+              .getContainerPath());
+          containerChunkInfoVerbose.setPipeline(keyLocation.getPipeline());
+          containerChunkInfoVerbose.setChunkInfos(chunkDetailsList);
+          containerChunkInfo.setFiles(chunkPaths);
+          containerChunkInfo.setPipelineID(
+              keyLocation.getPipeline().getId().getId());
+          Gson gson = new GsonBuilder().create();
+          if (isVerbose()) {
+            element = gson.toJsonTree(containerChunkInfoVerbose);
+          } else {
+            element = gson.toJsonTree(containerChunkInfo);
+          }
+          jsonObj.addProperty("Datanode-HostName", entry.getKey()
+              .getHostName());
+          jsonObj.addProperty("Datanode-IP", entry.getKey()
+              .getIpAddress());
+          jsonObj.addProperty("Container-ID", containerId);
+          jsonObj.addProperty("Block-ID", keyLocation.getLocalID());
+          jsonObj.add("Locations", element);
+          responseFromAllNodes.add(jsonObj);
         }
-        jsonObj.addProperty("Datanode-HostName", entry.getKey().getHostName());
-        jsonObj.addProperty("Datanode-IP", entry.getKey().getIpAddress());
-        jsonObj.addProperty("Container-ID", containerId);
-        jsonObj.addProperty("Block-ID", keyLocation.getLocalID());
-        jsonObj.add("Locations", element);
-        responseFromAllNodes.add(jsonObj);
+        responseArrayList.add(responseFromAllNodes);
         xceiverClientManager.releaseClientForReadData(xceiverClient, false);
+        xceiverClient = null;
       }
-      responseArrayList.add(responseFromAllNodes);
+      result.add("KeyLocations", responseArrayList);
+      Gson gson2 = new GsonBuilder().setPrettyPrinting().create();
+      String prettyJson = gson2.toJson(result);
+      System.out.println(prettyJson);
+    } finally {
+      xceiverClientManager.close();
+      containerOperationClient.close();
+      ozoneManagerClient.close();

Review Comment:
   `xceiverClientManager` is closed in `ContainerOperationClient#close`, and I don't think we usually close the `OzoneManagerClient` obtained from `RpcClient`.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ChunkKeyHandler.java:
##########
@@ -71,124 +72,130 @@ public class ChunkKeyHandler extends KeyHandler implements
   private XceiverClientSpi xceiverClient;
   private OzoneManagerProtocol ozoneManagerClient;
 
+  @CommandLine.ParentCommand
+  private OzoneDebug parent;
+
   private String getChunkLocationPath(String containerLocation) {
     return containerLocation + File.separator + OzoneConsts.STORAGE_DIR_CHUNKS;
   }
 
   @Override
   protected void execute(OzoneClient client, OzoneAddress address)
           throws IOException, OzoneClientException {
-    containerOperationClient = new
-            ContainerOperationClient(createOzoneConfiguration());
-    xceiverClientManager = containerOperationClient
-            .getXceiverClientManager();
-    ozoneManagerClient = client.getObjectStore().getClientProxy()
-            .getOzoneManagerClient();
-    address.ensureKeyAddress();
-    JsonElement element;
-    JsonObject result = new JsonObject();
-    String volumeName = address.getVolumeName();
-    String bucketName = address.getBucketName();
-    String keyName = address.getKeyName();
-    List<ContainerProtos.ChunkInfo> tempchunks = null;
-    List<ChunkDetails> chunkDetailsList = new ArrayList<ChunkDetails>();
-    HashSet<String> chunkPaths = new HashSet<>();
-    OmKeyArgs keyArgs = new OmKeyArgs.Builder()
-            .setVolumeName(volumeName)
-            .setBucketName(bucketName)
-            .setKeyName(keyName)
-            .build();
-    OmKeyInfo keyInfo = ozoneManagerClient.lookupKey(keyArgs);
-    // querying  the keyLocations.The OM is queried to get containerID and
-    // localID pertaining to a given key
-    List<OmKeyLocationInfo> locationInfos = keyInfo
-            .getLatestVersionLocations().getBlocksLatestVersionOnly();
-    // for zero-sized key
-    if (locationInfos.isEmpty()) {
-      System.out.println("No Key Locations Found");
-      return;
-    }
-    ContainerLayoutVersion containerLayoutVersion = ContainerLayoutVersion
-            .getConfiguredVersion(getConf());
-    JsonArray responseArrayList = new JsonArray();
-    for (OmKeyLocationInfo keyLocation:locationInfos) {
-      ContainerChunkInfo containerChunkInfoVerbose = new ContainerChunkInfo();
-      ContainerChunkInfo containerChunkInfo = new ContainerChunkInfo();
-      long containerId = keyLocation.getContainerID();
-      chunkPaths.clear();
-      Pipeline pipeline = keyLocation.getPipeline();
-      if (pipeline.getType() != HddsProtos.ReplicationType.STAND_ALONE) {
-        pipeline = Pipeline.newBuilder(pipeline)
-            .setReplicationConfig(StandaloneReplicationConfig.getInstance(ONE))
-            .build();
-      }
-      xceiverClient = xceiverClientManager
-              .acquireClientForReadData(pipeline);
-      // Datanode is queried to get chunk information.Thus querying the
-      // OM,SCM and datanode helps us get chunk location information
-      ContainerProtos.DatanodeBlockID datanodeBlockID = keyLocation.getBlockID()
-              .getDatanodeBlockIDProtobuf();
-      // doing a getBlock on all nodes
-      HashMap<DatanodeDetails, ContainerProtos.GetBlockResponseProto>
-              responses = null;
-      try {
-        responses = ContainerProtocolCalls.getBlockFromAllNodes(
-            xceiverClient, datanodeBlockID, keyLocation.getToken());
-      } catch (InterruptedException e) {
-        LOG.error("Execution interrupted due to " + e);
-        Thread.currentThread().interrupt();
+    try {
+      containerOperationClient = new ContainerOperationClient(
+          parent.getOzoneConf());

Review Comment:
   Could be simplified by using `try-with-resources`.



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneDebugShell.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.shell;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdds.client.ReplicationFactor;
+import org.apache.hadoop.hdds.client.ReplicationType;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.replication.ReplicationManager;
+import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.client.ObjectStore;
+import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.client.OzoneClientFactory;
+import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
+import org.apache.hadoop.ozone.debug.OzoneDebug;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.ozone.test.GenericTestUtils;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;

Review Comment:
   Would be nice to use JUnit5 for new tests.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org