Repository: hbase
Updated Branches:
  refs/heads/0.98 44d410660 -> 1391cd919


HBASE-11845 HFile tool should implement Tool, disable blockcache by default

HFileTool now accepts configuration via -D arguments. The blockcache is
disabled by default.


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

Branch: refs/heads/0.98
Commit: 1391cd9197eb1aee7b2ae9e17b45604e3eb17fc8
Parents: 44d4106
Author: Nick Dimiduk <[email protected]>
Authored: Tue Sep 9 13:48:29 2014 -0700
Committer: Nick Dimiduk <[email protected]>
Committed: Thu Sep 11 14:46:33 2014 -0700

----------------------------------------------------------------------
 bin/hbase                                       |  2 +-
 .../org/apache/hadoop/hbase/io/hfile/HFile.java | 10 +++---
 .../hbase/io/hfile/HFilePrettyPrinter.java      | 36 +++++++++++++++-----
 3 files changed, 34 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1391cd91/bin/hbase
----------------------------------------------------------------------
diff --git a/bin/hbase b/bin/hbase
index ec0aabc..965aa6a 100755
--- a/bin/hbase
+++ b/bin/hbase
@@ -289,7 +289,7 @@ elif [ "$COMMAND" = "hbck" ] ; then
 elif [ "$COMMAND" = "hlog" ] ; then
   CLASS='org.apache.hadoop.hbase.regionserver.wal.HLogPrettyPrinter'
 elif [ "$COMMAND" = "hfile" ] ; then
-  CLASS='org.apache.hadoop.hbase.io.hfile.HFile'
+  CLASS='org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter'
 elif [ "$COMMAND" = "zkcli" ] ; then
   CLASS="org.apache.hadoop.hbase.zookeeper.ZooKeeperMainServer"
 elif [ "$COMMAND" = "upgrade" ] ; then

http://git-wip-us.apache.org/repos/asf/hbase/blob/1391cd91/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java
index 7eff10a..dd09987 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java
@@ -779,11 +779,6 @@ public class HFile {
     return res;
   }
 
-  public static void main(String[] args) throws IOException {
-    HFilePrettyPrinter prettyPrinter = new HFilePrettyPrinter();
-    System.exit(prettyPrinter.run(args));
-  }
-
   /**
    * Checks the given {@link HFile} format version, and throws an exception if
    * invalid. Note that if the version number comes from an input file and has
@@ -801,4 +796,9 @@ public class HFile {
           + MAX_FORMAT_VERSION + ")");
     }
   }
+
+  public static void main(String[] args) throws Exception {
+    // delegate to preserve old behavior
+    HFilePrettyPrinter.main(args);
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/1391cd91/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
index d62177a..37a5b06 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
@@ -43,8 +43,10 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HRegionInfo;
@@ -58,13 +60,15 @@ import org.apache.hadoop.hbase.util.ByteBloomFilter;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.FSUtils;
 import org.apache.hadoop.hbase.util.Writables;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
 
 /**
  * Implements pretty-printing functionality for {@link HFile}s.
  */
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
-public class HFilePrettyPrinter {
+public class HFilePrettyPrinter extends Configured implements Tool {
 
   private static final Log LOG = LogFactory.getLog(HFilePrettyPrinter.class);
 
@@ -84,7 +88,6 @@ public class HFilePrettyPrinter {
    * The row which the user wants to specify and print all the KeyValues for.
    */
   private byte[] row = null;
-  private Configuration conf;
 
   private List<Path> files = new ArrayList<Path>();
   private int count;
@@ -92,6 +95,16 @@ public class HFilePrettyPrinter {
   private static final String FOUR_SPACES = "    ";
 
   public HFilePrettyPrinter() {
+    super();
+    init();
+  }
+
+  public HFilePrettyPrinter(Configuration conf) {
+    super(conf);
+    init();
+  }
+
+  private void init() {
     options.addOption("v", "verbose", false,
         "Verbose output; emits file and meta data delimiters");
     options.addOption("p", "printkv", false, "Print key/value pairs");
@@ -148,13 +161,13 @@ public class HFilePrettyPrinter {
       String regionName = cmd.getOptionValue("r");
       byte[] rn = Bytes.toBytes(regionName);
       byte[][] hri = HRegionInfo.parseRegionName(rn);
-      Path rootDir = FSUtils.getRootDir(conf);
+      Path rootDir = FSUtils.getRootDir(getConf());
       Path tableDir = FSUtils.getTableDir(rootDir, TableName.valueOf(hri[0]));
       String enc = HRegionInfo.encodeRegionName(rn);
       Path regionDir = new Path(tableDir, enc);
       if (verbose)
         System.out.println("region dir -> " + regionDir);
-      List<Path> regionFiles = HFile.getStoreFiles(FileSystem.get(conf),
+      List<Path> regionFiles = HFile.getStoreFiles(FileSystem.get(getConf()),
           regionDir);
       if (verbose)
         System.out.println("Number of region files found -> "
@@ -177,9 +190,8 @@ public class HFilePrettyPrinter {
    * exit code (zero for success, non-zero for failure).
    */
   public int run(String[] args) {
-    conf = HBaseConfiguration.create();
     try {
-      FSUtils.setFsDefault(conf, FSUtils.getRootDir(conf));
+      FSUtils.setFsDefault(getConf(), FSUtils.getRootDir(getConf()));
       if (!parseOptions(args))
         return 1;
     } catch (IOException ex) {
@@ -209,12 +221,12 @@ public class HFilePrettyPrinter {
   private void processFile(Path file) throws IOException {
     if (verbose)
       System.out.println("Scanning -> " + file);
-    FileSystem fs = file.getFileSystem(conf);
+    FileSystem fs = file.getFileSystem(getConf());
     if (!fs.exists(file)) {
       System.err.println("ERROR, file doesnt exist: " + file);
     }
 
-    HFile.Reader reader = HFile.createReader(fs, file, new CacheConfig(conf), 
conf);
+    HFile.Reader reader = HFile.createReader(fs, file, new 
CacheConfig(getConf()), getConf());
 
     Map<byte[], byte[]> fileInfo = reader.loadFileInfo();
 
@@ -484,4 +496,12 @@ public class HFilePrettyPrinter {
       stream.printf(Locale.getDefault(), "             count = %d\n", 
histogram.count());
     }
   }
+
+  public static void main(String[] args) throws Exception {
+    Configuration conf = HBaseConfiguration.create();
+    // no need for a block cache
+    conf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0);
+    int ret = ToolRunner.run(conf, new HFilePrettyPrinter(), args);
+    System.exit(ret);
+  }
 }

Reply via email to