adoroszlai commented on code in PR #8016: URL: https://github.com/apache/ozone/pull/8016#discussion_r2066027884
########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/om/CompactionLogDagPrinter.java: ########## @@ -0,0 +1,115 @@ +/* + * 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.protobuf.InvalidProtocolBufferException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.Callable; +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.hadoop.ozone.graph.PrintableGraph; +import org.apache.ozone.compaction.log.CompactionLogEntry; +import org.apache.ozone.rocksdiff.CompactionDag; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; + +/** + * Handler to generate image for current compaction DAG. + * 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; + + @Override + public Void call() throws Exception { + try { + final List<ColumnFamilyHandle> cfHandleList = new ArrayList<>(); + List<ColumnFamilyDescriptor> cfDescList = RocksDBUtils.getColumnFamilyDescriptors(dbPath); + ManagedRocksDB activeRocksDB = ManagedRocksDB.openReadOnly(dbPath, cfDescList, cfHandleList); + ColumnFamilyHandle compactionLogTableCFHandle = + RocksDBUtils.getColumnFamilyHandle(COMPACTION_LOG_TABLE, cfHandleList); + + CompactionDag compactionDag = new CompactionDag(); + loadCompactionDagFromDB(activeRocksDB, compactionLogTableCFHandle, compactionDag); + + pngPrintMutableGraph(compactionDag, imageLocation); + out().println("Graph was generated at '" + imageLocation + "'."); + } catch (RocksDBException ex) { + err().println("Failed to open RocksDB: " + ex); + throw new IOException(ex); + } + return null; + } + + /** + * Read a compactionLofTable and create entries in the dags. + */ + private void loadCompactionDagFromDB(ManagedRocksDB activeRocksDB, + ColumnFamilyHandle compactionLogTableCFHandle, + CompactionDag compactionDag) { Review Comment: nit: Please do not format method signature like this. Whenever visibility / return type / method name / other modifiers are changed, we would have to reindent all parameters. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/om/CompactionLogDagPrinter.java: ########## @@ -0,0 +1,115 @@ +/* + * 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.protobuf.InvalidProtocolBufferException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.Callable; +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.hadoop.ozone.graph.PrintableGraph; +import org.apache.ozone.compaction.log.CompactionLogEntry; +import org.apache.ozone.rocksdiff.CompactionDag; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; + +/** + * Handler to generate image for current compaction DAG. + * ozone debug om print-compaction-dag. + */ +@CommandLine.Command( + name = "print-compaction-dag", + aliases = "pcd", Review Comment: Do we need `print-`, i.e. is there any other operation we can do with compaction DAG? Image is saved to a file, not printed to stdout. If we need any prefix, maybe `generate-` would be better. ########## hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/client/ClientProtocolStub.java: ########## @@ -724,6 +724,7 @@ public OzoneSnapshot getSnapshotInfo(String volumeName, String bucketName, } @Override + @Deprecated Review Comment: Is it enough to add `@Deprecated` in the interface, and not all implementations? ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/graph/Edge.java: ########## @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.ozone.graph; Review Comment: Why do we need this change? `org.apache.hadoop.ozone` is "legacy" and does not need to be used for new packages. ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/om/CompactionLogDagPrinter.java: ########## @@ -0,0 +1,115 @@ +/* + * 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.protobuf.InvalidProtocolBufferException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.Callable; +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.hadoop.ozone.graph.PrintableGraph; +import org.apache.ozone.compaction.log.CompactionLogEntry; +import org.apache.ozone.rocksdiff.CompactionDag; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; + +/** + * Handler to generate image for current compaction DAG. + * 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; + + @Override + public Void call() throws Exception { + try { + final List<ColumnFamilyHandle> cfHandleList = new ArrayList<>(); + List<ColumnFamilyDescriptor> cfDescList = RocksDBUtils.getColumnFamilyDescriptors(dbPath); + ManagedRocksDB activeRocksDB = ManagedRocksDB.openReadOnly(dbPath, cfDescList, cfHandleList); + ColumnFamilyHandle compactionLogTableCFHandle = + RocksDBUtils.getColumnFamilyHandle(COMPACTION_LOG_TABLE, cfHandleList); + + CompactionDag compactionDag = new CompactionDag(); + loadCompactionDagFromDB(activeRocksDB, compactionLogTableCFHandle, compactionDag); + + pngPrintMutableGraph(compactionDag, imageLocation); + out().println("Graph was generated at '" + imageLocation + "'."); + } catch (RocksDBException ex) { + err().println("Failed to open RocksDB: " + ex); + throw new IOException(ex); Review Comment: Do we need to wrap in `IOException`? ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/om/OMDebug.java: ########## @@ -28,7 +28,8 @@ name = "om", description = "Debug commands related to OM.", subcommands = { - PrefixParser.class + PrefixParser.class, + CompactionLogDagPrinter.class Review Comment: nit: Let's add in alphabetical order. ########## hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/graph/TestPrintableGraph.java: ########## @@ -63,14 +63,10 @@ void testPrintNoGraphMessage(PrintableGraph.GraphType graphType) { @EnumSource(PrintableGraph.GraphType.class) void testPrintActualGraph(PrintableGraph.GraphType graphType) throws IOException { Set<CompactionNode> nodes = Stream.of( - new CompactionNode("fileName1", - 100, 100, "startKey1", "endKey1", "columnFamily1"), - new CompactionNode("fileName2", - 200, 200, "startKey2", "endKey2", null), - new CompactionNode("fileName3", - 300, 300, null, "endKey3", "columnFamily3"), - new CompactionNode("fileName4", - 400, 400, "startKey4", null, "columnFamily4") + new CompactionNode("fileName1", 100, "startKey1", "endKey1", "columnFamily1"), + new CompactionNode("fileName2", 200, "startKey2", "endKey2", null), + new CompactionNode("fileName3", 300, null, "endKey3", "columnFamily3"), + new CompactionNode("fileName4", 400, "startKey4", null, "columnFamily4") Review Comment: nit: avoid formatting-only changes ########## hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/om/CompactionLogDagPrinter.java: ########## @@ -0,0 +1,115 @@ +/* + * 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.protobuf.InvalidProtocolBufferException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.Callable; +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.hadoop.ozone.graph.PrintableGraph; +import org.apache.ozone.compaction.log.CompactionLogEntry; +import org.apache.ozone.rocksdiff.CompactionDag; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.RocksDBException; +import picocli.CommandLine; + +/** + * Handler to generate image for current compaction DAG. + * 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; + Review Comment: Move this to `OMDebug` and remove similar option from `PrefixParser`? -- 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