You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/04/15 08:57:35 UTC

[GitHub] [ozone] guihecheng commented on a change in pull request #2070: HDDS-4976. Add container replica related commands to debug

guihecheng commented on a change in pull request #2070:
URL: https://github.com/apache/ozone/pull/2070#discussion_r613884426



##########
File path: hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/LocalContainerInfo.java
##########
@@ -0,0 +1,165 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import org.apache.hadoop.hdds.cli.GenericParentCommand;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType;
+import org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics;
+import org.apache.hadoop.ozone.container.common.impl.ContainerData;
+import org.apache.hadoop.ozone.container.common.impl.ContainerSet;
+import org.apache.hadoop.ozone.container.common.interfaces.Container;
+import org.apache.hadoop.ozone.container.common.interfaces.Handler;
+import org.apache.hadoop.ozone.container.common.volume.HddsVolume;
+import org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
+import org.apache.hadoop.ozone.container.ozoneimpl.ContainerController;
+import org.apache.hadoop.ozone.container.ozoneimpl.ContainerReader;
+
+import org.kohsuke.MetaInfServices;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.ParentCommand;
+
+@Command(name = "localcontainerinfo",
+    description = "Show container info of the containers in local datanode")
+@MetaInfServices(SubcommandWithParent.class)
+public class LocalContainerInfo implements SubcommandWithParent,
+    Callable<Void> {
+
+  @ParentCommand
+  private GenericParentCommand parent;
+
+  @CommandLine.Option(names = {"--container"},
+      required = false,
+      description = "Container Id")
+  private long containerId;
+
+  @Override
+  public Class<?> getParentType() {
+    return OzoneDebug.class;
+  }
+
+  @Override
+  public Void call() throws Exception {
+
+    ConfigurationSource conf = parent.createOzoneConfiguration();
+
+    ContainerSet containerSet = new ContainerSet();
+
+    ContainerMetrics metrics = ContainerMetrics.create(conf);
+
+    String firstStorageDir = ContainerUtils.getFirstStorageDir(conf);
+
+    String datanodeUuid = ContainerUtils.getDatanodeUUID(firstStorageDir, conf);
+
+    String scmId = ContainerUtils.getScmId(firstStorageDir);
+
+    MutableVolumeSet volumeSet = new MutableVolumeSet(datanodeUuid, conf);
+
+    Map<ContainerType, Handler> handlers = new HashMap<>();
+
+    for (ContainerType containerType : ContainerType.values()) {
+      final Handler handler =
+          Handler.getHandlerForContainerType(
+              containerType,
+              conf,
+              datanodeUuid,
+              containerSet,
+              volumeSet,
+              metrics,
+              containerReplicaProto -> {
+              });
+      handler.setScmID(scmId);
+      handlers.put(containerType, handler);
+    }
+
+    ContainerController controller =
+        new ContainerController(containerSet, handlers);
+
+    Iterator<HddsVolume> volumeSetIterator = volumeSet.getVolumesList()
+        .iterator();
+
+    while (volumeSetIterator.hasNext()) {
+      HddsVolume volume = volumeSetIterator.next();
+      final ContainerReader reader =
+          new ContainerReader(volumeSet, volume, containerSet, conf);
+      reader.run();
+    }
+
+    if (containerId == 0L) {
+      Iterator<Container<?>> containerIt = controller.getContainers();
+      while (containerIt.hasNext()) {
+        Container container = containerIt.next();
+        outputContainer(container.getContainerData());
+      }
+    } else {
+      Container container = controller.getContainer(containerId);
+      if (container != null) {
+        outputContainer(container.getContainerData());
+      }
+    }
+
+    return null;
+  }
+
+  private void outputContainer(ContainerData data) throws IOException {
+    JsonObject result = new JsonObject();
+    result.addProperty("ContainerType", data.getContainerType().toString());
+    result.addProperty("ContainerID", data.getContainerID());
+    result.addProperty("LayoutVersion", data.getLayOutVersion().toString());
+    result.addProperty("ChunksPath", data.getChunksPath());
+    result.addProperty("State", data.getState().toString());
+    result.addProperty("MaxSize", data.getMaxSize());
+    result.addProperty("OriginPipelineId", data.getOriginPipelineId());
+    result.addProperty("OriginNodeId", data.getOriginNodeId());
+    result.addProperty("Volume", data.getVolume().toString());
+    result.addProperty("Checksum", data.getChecksum());
+    result.addProperty("DataScanTimestamp", data.getDataScanTimestamp());
+
+    switch (data.getContainerType()) {
+    case KeyValueContainer:
+      KeyValueContainerData kvData = (KeyValueContainerData)data;
+      result.addProperty("MetadataPath", kvData.getMetadataPath());
+      result.addProperty("ContainerDBType", kvData.getContainerDBType());
+      result.addProperty("DbFile", kvData.getDbFile().getPath());
+      result.addProperty("SchemaVersion", kvData.getSchemaVersion());
+      result.addProperty("DeleteTransactionId",
+          kvData.getDeleteTransactionId());
+      result.addProperty("BlockCommitSequenceId",
+          kvData.getBlockCommitSequenceId());
+    default:
+      break;
+    }
+
+    Gson gson2 = new GsonBuilder().setPrettyPrinting().create();
+    System.out.println(gson2.toJson(result));

Review comment:
       Hi @adoroszlai , now we are using this JsonUtils to dump more detailed output~




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

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