Liyin added you to the CC list for the revision "[jira] [HBASE-4698] Let the 
HFile Pretty Printer print all the key values for a specific row.".
Reviewers: mbautin, Kannan, jgray, gqchen, nspiegelberg

  HBase-4698 Let the HFile Pretty Printer print all the key values for a 
specific row.

  When using HFile Pretty Printer to debug HBase issues,
  it would very nice to allow the Pretty Printer to seek to a specific row, and 
only print all the key values for this row.


TEST PLAN
  tested this feature on dev cluster and running all the unit tests.

REVISION DETAIL
  https://reviews.facebook.net/D111

AFFECTED FILES
  src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
Index: src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
===================================================================
--- src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
+++ src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
@@ -41,7 +41,6 @@
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.io.hfile.HFile.FileInfo;
-import org.apache.hadoop.hbase.io.hfile.HFileBlockIndex.BlockIndexReader;
 import org.apache.hadoop.hbase.regionserver.TimeRangeTracker;
 import org.apache.hadoop.hbase.util.BloomFilter;
 import org.apache.hadoop.hbase.util.BloomFilterFactory;
@@ -68,7 +67,8 @@
   private boolean printBlocks;
   private boolean checkRow;
   private boolean checkFamily;
-
+  private boolean isSeekToRow = false;
+  private byte[] startKey = null;
   private Configuration conf;
 
   private List<Path> files = new ArrayList<Path>();
@@ -92,6 +92,8 @@
     options.addOption("a", "checkfamily", false, "Enable family check");
     options.addOption("f", "file", true,
         "File to scan. Pass full-path; e.g. hdfs://a:9000/hbase/.META./12/34");
+    options.addOption("s", "seekToRow", true,
+        "Seek to this row and print all the kvs for this row only");
     options.addOption("r", "region", true,
         "Region to scan. Pass region name; e.g. '.META.,,1'");
   }
@@ -125,6 +127,16 @@
       files.add(new Path(cmd.getOptionValue("f")));
     }
 
+    if (cmd.hasOption("s")) {
+      String key = cmd.getOptionValue("s");
+      if (key!= null && key.length() != 0) {
+        startKey = key.getBytes();
+        isSeekToRow = true;
+        System.out.println("Only print the kv for the row: " +
+					Bytes.toString(startKey));
+      }
+    }
+
     if (cmd.hasOption("r")) {
       String regionName = cmd.getOptionValue("r");
       byte[] rn = Bytes.toBytes(regionName);
@@ -203,8 +215,12 @@
     if (printKey || checkRow || checkFamily) {
       // scan over file and read key/value's, performing any requested checks
       HFileScanner scanner = reader.getScanner(false, false, false);
-      scanner.seekTo();
-      scanKeyValues(file, scanner);
+      if (this.isSeekToRow) {
+        scanner.seekTo(KeyValue.createFirstOnRow(this.startKey).getKey());
+      } else {
+        scanner.seekTo();
+      }
+      scanKeyValues(file, scanner, this.startKey);
     }
 
     // print meta data
@@ -220,7 +236,7 @@
     reader.close();
   }
 
-  private void scanKeyValues(Path file, HFileScanner scanner)
+  private void scanKeyValues(Path file, HFileScanner scanner, byte[] row)
       throws IOException {
     KeyValue pkv = null;
     boolean first = true;
@@ -230,6 +246,18 @@
       System.out.print("[");
     do {
       KeyValue kv = scanner.getKeyValue();
+      if (row != null && row.length != 0) {
+        int result = Bytes.compareTo(kv.getRow(), row);
+        if (result > 0) {
+          System.out.println("All the data for row " +
+              Bytes.toString(row) + " has been printed out");
+          break;
+        } else if (result < 0) {
+          System.out.println("Start to scan for the row: " +
+              Bytes.toString(row));
+          continue;
+        }
+      }
       // check if rows are in order
       if (checkRow && pkv != null) {
         if (Bytes.compareTo(pkv.getRow(), kv.getRow()) > 0) {

Reply via email to