hemantk-12 commented on code in PR #8016:
URL: https://github.com/apache/ozone/pull/8016#discussion_r2032103738


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/om/CompactionLogDagPrinter.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
+ *
+ *      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.om;
+
+import static org.apache.hadoop.ozone.OzoneConsts.COMPACTION_LOG_TABLE;
+
+import com.google.common.graph.GraphBuilder;
+import com.google.common.graph.MutableGraph;
+import com.google.protobuf.InvalidProtocolBufferException;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.hadoop.hdds.cli.AbstractSubcommand;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
+import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksIterator;
+import org.apache.hadoop.ozone.debug.RocksDBUtils;
+import org.apache.ozone.compaction.log.CompactionDagHelper;
+import org.apache.ozone.compaction.log.CompactionFileInfo;
+import org.apache.ozone.compaction.log.CompactionLogEntry;
+import org.apache.ozone.graph.PrintableGraph;
+import org.apache.ozone.rocksdiff.CompactionNode;
+import org.rocksdb.ColumnFamilyDescriptor;
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.RocksDBException;
+import picocli.CommandLine;
+
+/**
+ * Handler to generate image for current compaction DAG in the OM leader node.
+ * ozone debug om print-compaction-dag.
+ */
+@CommandLine.Command(
+    name = "print-compaction-dag",
+    aliases = "pcd",
+    description = "Create an image of the current compaction log DAG. " +
+        "This command is an offline command. i.e., it can run on any instance 
of om.db " +
+        "and does not require OM to be up.")
+public class CompactionLogDagPrinter extends AbstractSubcommand implements 
Callable<Void> {
+
+  @CommandLine.Option(names = {"-o", "--output-file"},
+      required = true,
+      description = "Path to location at which image will be downloaded. " +
+          "Should include the image file name with \".png\" extension.")
+  private String imageLocation;
+
+  @CommandLine.Option(names = {"--db"},
+      required = true,
+      scope = CommandLine.ScopeType.INHERIT,
+      description = "Path to OM RocksDB")
+  private String dbPath;
+
+  @CommandLine.Option(names = {"--compaction-log"},
+      scope = CommandLine.ScopeType.INHERIT,
+      description = "Path to compaction-log directory.")
+  private String compactionLogDir;
+
+  // TODO: Change graphType to enum.
+  @CommandLine.Option(names = {"-t", "--graph-type"},
+      description = "Type of node name to use in the graph image. (optional)\n 
Accepted values are: \n" +
+          "  FILE_NAME (default) : to use file name as node name in DAG,\n" +
+          "  KEY_SIZE: to show the no. of keys in the file along with file 
name in the DAG node name,\n" +
+          "  CUMULATIVE_SIZE: to show the cumulative size along with file name 
in the DAG node name.",
+      defaultValue = "FILE_NAME")
+  private String graphType;
+
+  @Override
+  public Void call() throws Exception {
+    try {
+      CreateCompactionDag createCompactionDag = new 
CreateCompactionDag(dbPath, compactionLogDir);
+      createCompactionDag.pngPrintMutableGraph(imageLocation, 
PrintableGraph.GraphType.valueOf(graphType));
+      out().println("Graph was generated at '" + imageLocation + "'.");
+    } catch (RocksDBException ex) {
+      err().println("Failed to open RocksDB: " + ex);
+      throw new IOException(ex);
+    }
+    return null;
+  }
+
+  class CreateCompactionDag {
+    // Hash table to track CompactionNode for a given SST File.
+    private final ConcurrentHashMap<String, CompactionNode> compactionNodeMap =
+        new ConcurrentHashMap<>();
+    private final MutableGraph<CompactionNode> backwardCompactionDAG =
+        GraphBuilder.directed().build();
+
+    private ColumnFamilyHandle compactionLogTableCFHandle;
+    private ManagedRocksDB activeRocksDB;
+    private CompactionDagHelper compactionDagHelper;
+
+    CreateCompactionDag(String dbPath, String compactDir) throws 
RocksDBException {
+      final List<ColumnFamilyHandle> cfHandleList = new ArrayList<>();
+      List<ColumnFamilyDescriptor> cfDescList = 
RocksDBUtils.getColumnFamilyDescriptors(dbPath);
+      activeRocksDB = ManagedRocksDB.openReadOnly(dbPath, cfDescList, 
cfHandleList);
+      compactionLogTableCFHandle = 
RocksDBUtils.getColumnFamilyHandle(COMPACTION_LOG_TABLE, cfHandleList);
+      compactionDagHelper = new CompactionDagHelper(compactDir, activeRocksDB, 
compactionLogTableCFHandle);
+    }
+
+    public void pngPrintMutableGraph(String filePath, PrintableGraph.GraphType 
gType)
+        throws IOException, RocksDBException {
+      Objects.requireNonNull(filePath, "Image file path is required.");
+      Objects.requireNonNull(gType, "Graph type is required.");
+
+      loadAllCompactionLogs();
+
+      PrintableGraph graph;

Review Comment:
   Can you please do the following as well?
   
   1. Mark 
[printCompactionLogDag](https://github.com/apache/ozone/blob/2b48e8c6ec1739d541d5c02183ad1a91d9f7a308/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/protocolPB/OzoneManagerRequestHandler.java#L1455)
 deprecated.
   2. Remove it form 
[RpcClient](https://github.com/apache/ozone/blob/2b48e8c6ec1739d541d5c02183ad1a91d9f7a308/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java#L1031),
 
[ClientProtocol](https://github.com/apache/ozone/blob/2b48e8c6ec1739d541d5c02183ad1a91d9f7a308/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/protocol/ClientProtocol.java)
 and 
[ObjectStore](https://github.com/apache/ozone/blob/2b48e8c6ec1739d541d5c02183ad1a91d9f7a308/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java).
   



-- 
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-unsubscr...@ozone.apache.org

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


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

Reply via email to