Repository: hbase
Updated Branches:
  refs/heads/0.94 83b4a1ee9 -> 0cc71fb2e
  refs/heads/0.98 1b2a05c94 -> 180034b75
  refs/heads/branch-1 3b2de6233 -> 39caf5757
  refs/heads/master ea085c637 -> c88b4c46a


HBASE-11450 Improve file size info in SnapshotInfo tool


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/0cc71fb2
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/0cc71fb2
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/0cc71fb2

Branch: refs/heads/0.94
Commit: 0cc71fb2e7e18b436bd6d01cabf6f0c4076d202d
Parents: 83b4a1e
Author: Matteo Bertozzi <matteo.berto...@cloudera.com>
Authored: Wed Jul 2 18:23:57 2014 +0200
Committer: Matteo Bertozzi <matteo.berto...@cloudera.com>
Committed: Wed Jul 2 18:23:57 2014 +0200

----------------------------------------------------------------------
 .../hadoop/hbase/snapshot/SnapshotInfo.java     | 31 +++++++++++++++-----
 1 file changed, 23 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/0cc71fb2/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java 
b/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java
index b8ba593..fc416cd 100644
--- a/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java
+++ b/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java
@@ -100,6 +100,12 @@ public final class SnapshotInfo extends Configured 
implements Tool {
       public long getSize() {
         return this.size;
       }
+
+      String getStateToString() {
+        if (isMissing()) return "NOT FOUND";
+        if (inArchive()) return "archive";
+        return null;
+      }
     }
 
     private int hfileArchiveCount = 0;
@@ -247,6 +253,7 @@ public final class SnapshotInfo extends Configured 
implements Tool {
     }
   }
 
+  private boolean printSizeInBytes = false;
   private FileSystem fs;
   private Path rootDir;
 
@@ -283,6 +290,8 @@ public final class SnapshotInfo extends Configured 
implements Tool {
           FSUtils.setRootDir(conf, sourceDir);
         } else if (cmd.equals("-list-snapshots")) {
           listSnapshots = true;
+        } else if (cmd.equals("-size-in-bytes")) {
+          printSizeInBytes = true;
         } else if (cmd.equals("-h") || cmd.equals("--help")) {
           printUsageAndExit();
         } else {
@@ -392,10 +401,11 @@ public final class SnapshotInfo extends Configured 
implements Tool {
           SnapshotStats.FileInfo info = stats.addStoreFile(region, family, 
hfile);
 
           if (showFiles) {
+            String state = info.getStateToString();
             System.out.printf("%8s %s/%s/%s/%s %s%n",
-              (info.isMissing() ? "-" : 
StringUtils.humanReadableInt(info.getSize())),
+              (info.isMissing() ? "-" : fileSizeToString(info.getSize())),
               table, region, family, hfile,
-              (info.inArchive() ? "(archive)" : info.isMissing() ? "(NOT 
FOUND)" : ""));
+              state == null ? "" : "(" + state + ")");
           }
         }
 
@@ -405,7 +415,7 @@ public final class SnapshotInfo extends Configured 
implements Tool {
 
           if (showFiles) {
             System.out.printf("%8s recovered.edits %s on region %s%n",
-              StringUtils.humanReadableInt(info.getSize()), logfile, region);
+              fileSizeToString(info.getSize()), logfile, region);
           }
         }
 
@@ -414,10 +424,11 @@ public final class SnapshotInfo extends Configured 
implements Tool {
           SnapshotStats.FileInfo info = stats.addLogFile(server, logfile);
 
           if (showFiles) {
+            String state = info.getStateToString();
             System.out.printf("%8s log %s on server %s %s%n",
-              (info.isMissing() ? "-" : 
StringUtils.humanReadableInt(info.getSize())),
+              (info.isMissing() ? "-" : fileSizeToString(info.getSize())),
               logfile, server,
-              (info.isMissing() ? "(NOT FOUND)" : ""));
+              state == null ? "" : "(" + state + ")");
           }
         }
     });
@@ -434,16 +445,20 @@ public final class SnapshotInfo extends Configured 
implements Tool {
     if (showStats) {
       System.out.printf("%d HFiles (%d in archive), total size %s (%.2f%% %s 
shared with the source table)%n",
         stats.getStoreFilesCount(), stats.getArchivedStoreFilesCount(),
-        StringUtils.humanReadableInt(stats.getStoreFilesSize()),
+        fileSizeToString(stats.getStoreFilesSize()),
         stats.getSharedStoreFilePercentage(),
-        StringUtils.humanReadableInt(stats.getSharedStoreFilesSize())
+        fileSizeToString(stats.getSharedStoreFilesSize())
       );
       System.out.printf("%d Logs, total size %s%n",
-        stats.getLogsCount(), 
StringUtils.humanReadableInt(stats.getLogsSize()));
+        stats.getLogsCount(), fileSizeToString(stats.getLogsSize()));
       System.out.println();
     }
   }
 
+  private String fileSizeToString(long size) {
+    return printSizeInBytes ? Long.toString(size) : 
StringUtils.humanReadableInt(size);
+  }
+
   private void printUsageAndExit() {
     System.err.printf("Usage: bin/hbase %s [options]%n", getClass().getName());
     System.err.println(" where [options] are:");

Reply via email to