goiri commented on code in PR #5155:
URL: https://github.com/apache/hadoop/pull/5155#discussion_r1029857848


##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java:
##########
@@ -97,6 +106,7 @@
 public class RouterAdmin extends Configured implements Tool {
 
   private static final Logger LOG = LoggerFactory.getLogger(RouterAdmin.class);
+  private static final String DUMP_COMMAND = "-dumpState";

Review Comment:
   As you are at it, can you add a constant for all the others?



##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java:
##########
@@ -1301,6 +1327,46 @@ private int refreshCallQueue() throws IOException {
     return returnCode;
   }
 
+  /**
+   * Dumps the contents of the StateStore to stdout.
+   * @return true if it was successful
+   */
+  public static boolean dumpStateStore(Configuration conf,
+                                PrintStream output) throws IOException {
+    StateStoreService service = new StateStoreService();
+    conf.setBoolean(RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE, false);
+    service.init(conf);
+    service.loadDriver();
+    if (!service.isDriverReady()) {
+      System.err.println("Can't initialize driver");
+      return false;
+    }
+    // Get the stores sorted by name
+    Map<String, RecordStore<? extends BaseRecord>> stores = new TreeMap<>();
+    for(RecordStore<? extends BaseRecord> store: service.getRecordStores()) {
+      stores.put(StateStoreUtils.getRecordName(store.getRecordClass()), store);
+    }
+    for (Entry<String, RecordStore<? extends BaseRecord>> pair: 
stores.entrySet()) {
+      output.println(String.format("---- %s ----", pair.getKey()));
+      if (pair.getValue() instanceof CachedRecordStore) {
+        for (Object record: ((CachedRecordStore) 
pair.getValue()).getCachedRecords()) {
+          if (record instanceof BaseRecord) {
+            BaseRecord baseRecord = (BaseRecord) record;
+            if (record instanceof PBRecord) {

Review Comment:
   Can we just check for this right away? I think they instanceof was for 
baseRecord



##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java:
##########
@@ -1301,6 +1327,46 @@ private int refreshCallQueue() throws IOException {
     return returnCode;
   }
 
+  /**
+   * Dumps the contents of the StateStore to stdout.
+   * @return true if it was successful
+   */
+  public static boolean dumpStateStore(Configuration conf,
+                                PrintStream output) throws IOException {
+    StateStoreService service = new StateStoreService();
+    conf.setBoolean(RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE, false);
+    service.init(conf);
+    service.loadDriver();
+    if (!service.isDriverReady()) {
+      System.err.println("Can't initialize driver");
+      return false;
+    }
+    // Get the stores sorted by name
+    Map<String, RecordStore<? extends BaseRecord>> stores = new TreeMap<>();
+    for(RecordStore<? extends BaseRecord> store: service.getRecordStores()) {
+      stores.put(StateStoreUtils.getRecordName(store.getRecordClass()), store);

Review Comment:
   Extract the first chunk
   ```
   String recordName = StateStoreUtils.getRecordName(store.getRecordClass());
   ```



##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java:
##########
@@ -1301,6 +1327,46 @@ private int refreshCallQueue() throws IOException {
     return returnCode;
   }
 
+  /**
+   * Dumps the contents of the StateStore to stdout.
+   * @return true if it was successful
+   */
+  public static boolean dumpStateStore(Configuration conf,
+                                PrintStream output) throws IOException {
+    StateStoreService service = new StateStoreService();
+    conf.setBoolean(RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE, false);
+    service.init(conf);
+    service.loadDriver();
+    if (!service.isDriverReady()) {
+      System.err.println("Can't initialize driver");
+      return false;
+    }
+    // Get the stores sorted by name
+    Map<String, RecordStore<? extends BaseRecord>> stores = new TreeMap<>();
+    for(RecordStore<? extends BaseRecord> store: service.getRecordStores()) {
+      stores.put(StateStoreUtils.getRecordName(store.getRecordClass()), store);
+    }
+    for (Entry<String, RecordStore<? extends BaseRecord>> pair: 
stores.entrySet()) {
+      output.println(String.format("---- %s ----", pair.getKey()));
+      if (pair.getValue() instanceof CachedRecordStore) {
+        for (Object record: ((CachedRecordStore) 
pair.getValue()).getCachedRecords()) {
+          if (record instanceof BaseRecord) {
+            BaseRecord baseRecord = (BaseRecord) record;
+            if (record instanceof PBRecord) {
+              output.println(String.format("  %s:", 
baseRecord.getPrimaryKey()));
+              output.println("    " +

Review Comment:
   Extract the ((PBRecord) record).getProto() and possibly the toString()



##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java:
##########
@@ -1301,6 +1327,46 @@ private int refreshCallQueue() throws IOException {
     return returnCode;
   }
 
+  /**
+   * Dumps the contents of the StateStore to stdout.
+   * @return true if it was successful
+   */
+  public static boolean dumpStateStore(Configuration conf,
+                                PrintStream output) throws IOException {
+    StateStoreService service = new StateStoreService();
+    conf.setBoolean(RBFConfigKeys.DFS_ROUTER_METRICS_ENABLE, false);
+    service.init(conf);
+    service.loadDriver();
+    if (!service.isDriverReady()) {
+      System.err.println("Can't initialize driver");
+      return false;
+    }
+    // Get the stores sorted by name
+    Map<String, RecordStore<? extends BaseRecord>> stores = new TreeMap<>();
+    for(RecordStore<? extends BaseRecord> store: service.getRecordStores()) {
+      stores.put(StateStoreUtils.getRecordName(store.getRecordClass()), store);
+    }
+    for (Entry<String, RecordStore<? extends BaseRecord>> pair: 
stores.entrySet()) {
+      output.println(String.format("---- %s ----", pair.getKey()));

Review Comment:
   Extract getKey and getValue



-- 
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: common-issues-unsubscr...@hadoop.apache.org

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


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

Reply via email to