mukul1987 commented on a change in pull request #945:
URL: https://github.com/apache/hadoop-ozone/pull/945#discussion_r427497390



##########
File path: 
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ListTables.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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 org.rocksdb.*;

Review comment:
       Please expand wildcard imports.

##########
File path: 
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ListTables.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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 org.rocksdb.*;
+import picocli.CommandLine;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+/**
+ * List all column Families/Tables in db.
+ */
[email protected](
+        name = "list",
+        description = "list all tables in db."
+)
+public class ListTables implements Callable<Void> {
+
+  @CommandLine.ParentCommand
+  private RDBParser parent;
+
+  @Override
+  public Void call() throws Exception {
+    List<byte[]> cfList = getColumnFamilyList(parent.getDbPath());
+    for (byte[] b : cfList) {
+      System.out.println(new String(b, StandardCharsets.UTF_8));
+    }
+    return null;
+  }
+
+  private static List<byte[]> getColumnFamilyList(String dbPath) {
+    List<byte[]> cfList = null;
+    try {
+      cfList = RocksDB.listColumnFamilies(new Options(), dbPath);
+    } catch (RocksDBException e) {
+      e.printStackTrace();

Review comment:
       after extending GenericCli, we will not need this change.

##########
File path: 
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/SCMDBParser.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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 org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition;
+import org.rocksdb.*;
+import picocli.CommandLine;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+/**
+ * Parser for scm.db file.
+ */
[email protected](
+        name = "scmdbparser",
+        description = "Parse specified metadataTable"
+)
+public class SCMDBParser implements Callable<Void> {
+
+  @CommandLine.Option(names = {"-table"},
+            description = "Table name")
+  private String tableName;
+
+  @CommandLine.ParentCommand
+  private RDBParser parent;
+
+
+  private static void displayTable(RocksDB rocksDB,
+        DBColumnFamilyDefinition dbColumnFamilyDefinition,
+        List<ColumnFamilyHandle> list) throws IOException {
+    ColumnFamilyHandle columnFamilyHandle = getColumnFamilyHandle(
+            dbColumnFamilyDefinition.getTableName()
+                    .getBytes(StandardCharsets.UTF_8), list);
+    RocksIterator iterator = rocksDB.newIterator(columnFamilyHandle);

Review comment:
       lets check for null here as if the table name doesn't match, we can 
throw NPE.

##########
File path: 
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/RDBParser.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition;
+import org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition;
+import picocli.CommandLine;
+
+import java.util.HashMap;
+
+/**
+ * Tool that parses rocksdb file.
+ */
[email protected](
+        name = "rdbparser",
+        description = "Parse rocksdb file content",
+        subcommands = {
+                SCMDBParser.class,
+                ListTables.class
+        })
+public class RDBParser extends GenericCli {
+
+  @CommandLine.Option(names = {"-path"},
+            description = "Database File Path")
+    private String dbPath;
+
+  public static HashMap<String, DBColumnFamilyDefinition>
+      getColumnFamilyMap() {
+    return columnFamilyMap;
+  }
+
+  private static HashMap<String, DBColumnFamilyDefinition>  columnFamilyMap;
+
+  public String getDbPath() {
+    return dbPath;
+  }
+
+  static {
+    columnFamilyMap = constructColumnFamilyMap();
+  }
+
+  private static HashMap<String, DBColumnFamilyDefinition>
+      constructColumnFamilyMap() {
+    columnFamilyMap = new HashMap<String, DBColumnFamilyDefinition>();

Review comment:
       This map should be constructed from SCM DB definition.

##########
File path: 
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/RDBParser.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.hadoop.hdds.cli.GenericCli;
+import org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition;
+import org.apache.hadoop.hdds.utils.db.DBColumnFamilyDefinition;
+import picocli.CommandLine;
+
+import java.util.HashMap;
+
+/**
+ * Tool that parses rocksdb file.
+ */
[email protected](
+        name = "rdbparser",
+        description = "Parse rocksdb file content",
+        subcommands = {
+                SCMDBParser.class,
+                ListTables.class
+        })
+public class RDBParser extends GenericCli {
+
+  @CommandLine.Option(names = {"-path"},
+            description = "Database File Path")
+    private String dbPath;
+
+  public static HashMap<String, DBColumnFamilyDefinition>
+      getColumnFamilyMap() {
+    return columnFamilyMap;
+  }
+
+  private static HashMap<String, DBColumnFamilyDefinition>  columnFamilyMap;
+
+  public String getDbPath() {
+    return dbPath;
+  }
+
+  static {
+    columnFamilyMap = constructColumnFamilyMap();
+  }
+
+  private static HashMap<String, DBColumnFamilyDefinition>
+      constructColumnFamilyMap() {
+    columnFamilyMap = new HashMap<String, DBColumnFamilyDefinition>();

Review comment:
       This can be replaced with getColumnFamilies, and then a table created 
out of that.




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to