You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2019/12/19 00:50:53 UTC

[hbase] branch branch-1 updated (afb2e34 -> 85b43a7)

This is an automated email from the ASF dual-hosted git repository.

apurtell pushed a change to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git.


    from afb2e34  HBASE-23362: [WalPrettyPrinter] print/filter by table name. (#898)
     new d77da0d  Revert "HBASE-23362: [WalPrettyPrinter] print/filter by table name. (#898)"
     new 85b43a7  HBASE-23362: [WalPrettyPrinter] print/filter by table name. (#898)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/hadoop/hbase/regionserver/wal/HLogPrettyPrinter.java  | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)


[hbase] 01/02: Revert "HBASE-23362: [WalPrettyPrinter] print/filter by table name. (#898)"

Posted by ap...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

apurtell pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git

commit d77da0dcfc98ea16d9faef801a5d4d96d2a03f4f
Author: Andrew Purtell <ap...@apache.org>
AuthorDate: Wed Dec 18 16:48:56 2019 -0800

    Revert "HBASE-23362: [WalPrettyPrinter] print/filter by table name. (#898)"
    
    This reverts commit afb2e348e604e7740bab0fe6b72a023b3faccd21.
---
 .../apache/hadoop/hbase/wal/WALPrettyPrinter.java  | 93 ++++++----------------
 1 file changed, 24 insertions(+), 69 deletions(-)

diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALPrettyPrinter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALPrettyPrinter.java
index 3248fc4..c440c07 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALPrettyPrinter.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALPrettyPrinter.java
@@ -43,7 +43,6 @@ import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
-import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.Tag;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.FSUtils;
@@ -52,8 +51,6 @@ import org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader;
 // imports for things that haven't moved yet.
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
 import org.apache.hbase.thirdparty.com.google.gson.Gson;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -72,17 +69,10 @@ import org.slf4j.LoggerFactory;
 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
 @InterfaceStability.Evolving
 public class WALPrettyPrinter {
-  private static final Logger LOG = LoggerFactory.getLogger(WALPrettyPrinter.class);
-
-  // Output template for pretty printing.
-  private static final String outputTmpl =
-      "Sequence=%s, table=%s, region=%s, at write timestamp=%s";
-
   private boolean outputValues;
   private boolean outputJSON;
   // The following enable filtering by sequence, region, and row, respectively
   private long sequence;
-  private String table;
   private String region;
   private String row;
   // enable in order to output a single list of transactions from several files
@@ -102,7 +92,6 @@ public class WALPrettyPrinter {
     outputValues = false;
     outputJSON = false;
     sequence = -1;
-    table = null;
     region = null;
     row = null;
     persistentOutput = false;
@@ -122,9 +111,6 @@ public class WALPrettyPrinter {
    * @param sequence
    *          when nonnegative, serves as a filter; only log entries with this
    *          sequence id will be printed
-   * @param table
-   *          when non null, serves as a filter. only entries corresponding to this
-   *          table will be printed.
    * @param region
    *          when not null, serves as a filter; only log entries from this
    *          region will be printed
@@ -139,12 +125,12 @@ public class WALPrettyPrinter {
    *          PrettyPrinter's output.
    */
   public WALPrettyPrinter(boolean outputValues, boolean outputJSON,
-      long sequence, String table, String region, String row, boolean persistentOutput,
+      long sequence, String region, String row, boolean
+      persistentOutput,
       PrintStream out) {
     this.outputValues = outputValues;
     this.outputJSON = outputJSON;
     this.sequence = sequence;
-    this.table = table;
     this.region = region;
     this.row = row;
     this.persistentOutput = persistentOutput;
@@ -195,13 +181,6 @@ public class WALPrettyPrinter {
   }
 
   /**
-   * Sets the table filter. Only log entries for this table are printed.
-   * @param table table name to set.
-   */
-  public void setTableFilter(String table) {
-    this.table = table;
-  }
-  /**
    * sets the region by which output will be filtered
    *
    * @param region
@@ -228,14 +207,12 @@ public class WALPrettyPrinter {
    * the case of JSON output.
    */
   public void beginPersistentOutput() {
-    if (persistentOutput) {
+    if (persistentOutput)
       return;
-    }
     persistentOutput = true;
     firstTxn = true;
-    if (outputJSON) {
+    if (outputJSON)
       out.print("[");
-    }
   }
 
   /**
@@ -243,13 +220,11 @@ public class WALPrettyPrinter {
    * case of JSON output.
    */
   public void endPersistentOutput() {
-    if (!persistentOutput) {
+    if (!persistentOutput)
       return;
-    }
     persistentOutput = false;
-    if (outputJSON) {
+    if (outputJSON)
       out.print("]");
-    }
   }
 
   /**
@@ -313,23 +288,16 @@ public class WALPrettyPrinter {
         Map<String, Object> txn = key.toStringMap();
         long writeTime = key.getWriteTime();
         // check output filters
-        if (table != null && !((TableName) txn.get("table")).toString().equals(table)) {
-          continue;
-        }
-        if (sequence >= 0 && ((Long) txn.get("sequence")) != sequence) {
+        if (sequence >= 0 && ((Long) txn.get("sequence")) != sequence)
           continue;
-        }
-        if (region != null && !txn.get("region").equals(region)) {
+        if (region != null && !((String) txn.get("region")).equals(region))
           continue;
-        }
         // initialize list into which we will store atomic actions
-        List<Map<String, Object>> actions = new ArrayList<Map<String, Object>>();
+        List<Map> actions = new ArrayList<Map>();
         for (Cell cell : edit.getCells()) {
           // add atomic operation to txn
-          Map<String, Object> op = new HashMap<>(toStringMap(cell));
-          if (outputValues) {
-            op.put("value", Bytes.toStringBinary(CellUtil.cloneValue(cell)));
-          }
+          Map<String, Object> op = new HashMap<String, Object>(toStringMap(cell));
+          if (outputValues) op.put("value", Bytes.toStringBinary(cell.getValue()));
           // check row output filter
           if (row == null || ((String) op.get("row")).equals(row)) {
             actions.add(op);
@@ -337,33 +305,29 @@ public class WALPrettyPrinter {
           op.put("total_size_sum", CellUtil.estimatedHeapSizeOf(cell));
 
         }
-        if (actions.isEmpty()) {
+        if (actions.size() == 0)
           continue;
-        }
         txn.put("actions", actions);
         if (outputJSON) {
           // JSON output is a straightforward "toString" on the txn object
-          if (firstTxn) {
+          if (firstTxn)
             firstTxn = false;
-          } else {
+          else
             out.print(",");
-          }
           // encode and print JSON
           out.print(GSON.toJson(txn));
         } else {
           // Pretty output, complete with indentation by atomic action
-          out.println(String.format(outputTmpl,
-              txn.get("sequence"), txn.get("table"), txn.get("region"), new Date(writeTime)));
+          out.println("Sequence=" + txn.get("sequence") + " "
+              + ", region=" + txn.get("region") + " at write timestamp=" + new Date(writeTime));
           for (int i = 0; i < actions.size(); i++) {
-            Map<String, Object> op = actions.get(i);
+            Map op = actions.get(i);
             out.println("row=" + op.get("row") +
                 ", column=" + op.get("family") + ":" + op.get("qualifier"));
             if (op.get("tag") != null) {
               out.println("    tag: " + op.get("tag"));
             }
-            if (outputValues) {
-              out.println("    value: " + op.get("value"));
-            }
+            if (outputValues) out.println("    value: " + op.get("value"));
             out.println("cell total size sum: " + op.get("total_size_sum"));
           }
         }
@@ -422,7 +386,6 @@ public class WALPrettyPrinter {
     options.addOption("h", "help", false, "Output help message");
     options.addOption("j", "json", false, "Output JSON");
     options.addOption("p", "printvals", false, "Print values");
-    options.addOption("t", "table", true, "Table name to filter by.");
     options.addOption("r", "region", true,
         "Region to filter by. Pass encoded region name; e.g. '9192caead6a5a20acb4454ffbc79fa14'");
     options.addOption("s", "sequence", true,
@@ -442,29 +405,21 @@ public class WALPrettyPrinter {
         System.exit(-1);
       }
       // configure the pretty printer using command line options
-      if (cmd.hasOption("p")) {
+      if (cmd.hasOption("p"))
         printer.enableValues();
-      }
-      if (cmd.hasOption("j")) {
+      if (cmd.hasOption("j"))
         printer.enableJSON();
-      }
-      if (cmd.hasOption("t")) {
-        printer.setTableFilter(cmd.getOptionValue("t"));
-      }
-      if (cmd.hasOption("r")) {
+      if (cmd.hasOption("r"))
         printer.setRegionFilter(cmd.getOptionValue("r"));
-      }
-      if (cmd.hasOption("s")) {
+      if (cmd.hasOption("s"))
         printer.setSequenceFilter(Long.parseLong(cmd.getOptionValue("s")));
-      }
-      if (cmd.hasOption("w")) {
+      if (cmd.hasOption("w"))
         printer.setRowFilter(cmd.getOptionValue("w"));
-      }
       if (cmd.hasOption("g")) {
         printer.setPosition(Long.parseLong(cmd.getOptionValue("g")));
       }
     } catch (ParseException e) {
-      LOG.error("Failed to parse commandLine arguments", e);
+      e.printStackTrace();
       HelpFormatter formatter = new HelpFormatter();
       formatter.printHelp("HFile filename(s) ", options, true);
       System.exit(-1);


[hbase] 02/02: HBASE-23362: [WalPrettyPrinter] print/filter by table name. (#898)

Posted by ap...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

apurtell pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git

commit 85b43a70598df338fd77f4d388893e78e84958c3
Author: Bharath Vissapragada <bh...@apache.org>
AuthorDate: Wed Dec 4 02:03:33 2019 -0800

    HBASE-23362: [WalPrettyPrinter] print/filter by table name. (#898)
    
    Reapplied with missing delta for branch-1
    
    Signed-off-by: Wellington Chevreuil <wc...@apache.org>
---
 .../hbase/regionserver/wal/HLogPrettyPrinter.java  |  9 ++-
 .../apache/hadoop/hbase/wal/WALPrettyPrinter.java  | 93 ++++++++++++++++------
 2 files changed, 75 insertions(+), 27 deletions(-)

diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogPrettyPrinter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogPrettyPrinter.java
index 898464a..9d4d445 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogPrettyPrinter.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogPrettyPrinter.java
@@ -67,7 +67,7 @@ public class HLogPrettyPrinter extends WALPrettyPrinter {
    * Basic constructor that simply initializes values to reasonable defaults.
    */
   public HLogPrettyPrinter() {
-    this(false, false, -1l, null, null, false, System.out);
+    this(false, false, -1l, null, null, null, false, System.out);
   }
 
   /**
@@ -82,6 +82,9 @@ public class HLogPrettyPrinter extends WALPrettyPrinter {
    * @param sequence
    *          when nonnegative, serves as a filter; only log entries with this
    *          sequence id will be printed
+   * @param table
+   *          when not null, serves as a filter; only log entries from this
+   *          table will be printed
    * @param region
    *          when not null, serves as a filter; only log entries from this
    *          region will be printed
@@ -96,9 +99,9 @@ public class HLogPrettyPrinter extends WALPrettyPrinter {
    *          PrettyPrinter's output.
    */
   public HLogPrettyPrinter(boolean outputValues, boolean outputJSON,
-      long sequence, String region, String row, boolean persistentOutput,
+      long sequence, String table, String region, String row, boolean persistentOutput,
       PrintStream out) {
-    super(outputValues, outputJSON, sequence, region, row, persistentOutput, out);
+    super(outputValues, outputJSON, sequence, table, region, row, persistentOutput, out);
   }
 
   public static void main(String[] args) throws IOException {
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALPrettyPrinter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALPrettyPrinter.java
index c440c07..3248fc4 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALPrettyPrinter.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALPrettyPrinter.java
@@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellUtil;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
+import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.Tag;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.FSUtils;
@@ -51,6 +52,8 @@ import org.apache.hadoop.hbase.regionserver.wal.ProtobufLogReader;
 // imports for things that haven't moved yet.
 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
 import org.apache.hbase.thirdparty.com.google.gson.Gson;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -69,10 +72,17 @@ import org.apache.hbase.thirdparty.com.google.gson.Gson;
 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
 @InterfaceStability.Evolving
 public class WALPrettyPrinter {
+  private static final Logger LOG = LoggerFactory.getLogger(WALPrettyPrinter.class);
+
+  // Output template for pretty printing.
+  private static final String outputTmpl =
+      "Sequence=%s, table=%s, region=%s, at write timestamp=%s";
+
   private boolean outputValues;
   private boolean outputJSON;
   // The following enable filtering by sequence, region, and row, respectively
   private long sequence;
+  private String table;
   private String region;
   private String row;
   // enable in order to output a single list of transactions from several files
@@ -92,6 +102,7 @@ public class WALPrettyPrinter {
     outputValues = false;
     outputJSON = false;
     sequence = -1;
+    table = null;
     region = null;
     row = null;
     persistentOutput = false;
@@ -111,6 +122,9 @@ public class WALPrettyPrinter {
    * @param sequence
    *          when nonnegative, serves as a filter; only log entries with this
    *          sequence id will be printed
+   * @param table
+   *          when non null, serves as a filter. only entries corresponding to this
+   *          table will be printed.
    * @param region
    *          when not null, serves as a filter; only log entries from this
    *          region will be printed
@@ -125,12 +139,12 @@ public class WALPrettyPrinter {
    *          PrettyPrinter's output.
    */
   public WALPrettyPrinter(boolean outputValues, boolean outputJSON,
-      long sequence, String region, String row, boolean
-      persistentOutput,
+      long sequence, String table, String region, String row, boolean persistentOutput,
       PrintStream out) {
     this.outputValues = outputValues;
     this.outputJSON = outputJSON;
     this.sequence = sequence;
+    this.table = table;
     this.region = region;
     this.row = row;
     this.persistentOutput = persistentOutput;
@@ -181,6 +195,13 @@ public class WALPrettyPrinter {
   }
 
   /**
+   * Sets the table filter. Only log entries for this table are printed.
+   * @param table table name to set.
+   */
+  public void setTableFilter(String table) {
+    this.table = table;
+  }
+  /**
    * sets the region by which output will be filtered
    *
    * @param region
@@ -207,12 +228,14 @@ public class WALPrettyPrinter {
    * the case of JSON output.
    */
   public void beginPersistentOutput() {
-    if (persistentOutput)
+    if (persistentOutput) {
       return;
+    }
     persistentOutput = true;
     firstTxn = true;
-    if (outputJSON)
+    if (outputJSON) {
       out.print("[");
+    }
   }
 
   /**
@@ -220,11 +243,13 @@ public class WALPrettyPrinter {
    * case of JSON output.
    */
   public void endPersistentOutput() {
-    if (!persistentOutput)
+    if (!persistentOutput) {
       return;
+    }
     persistentOutput = false;
-    if (outputJSON)
+    if (outputJSON) {
       out.print("]");
+    }
   }
 
   /**
@@ -288,16 +313,23 @@ public class WALPrettyPrinter {
         Map<String, Object> txn = key.toStringMap();
         long writeTime = key.getWriteTime();
         // check output filters
-        if (sequence >= 0 && ((Long) txn.get("sequence")) != sequence)
+        if (table != null && !((TableName) txn.get("table")).toString().equals(table)) {
+          continue;
+        }
+        if (sequence >= 0 && ((Long) txn.get("sequence")) != sequence) {
           continue;
-        if (region != null && !((String) txn.get("region")).equals(region))
+        }
+        if (region != null && !txn.get("region").equals(region)) {
           continue;
+        }
         // initialize list into which we will store atomic actions
-        List<Map> actions = new ArrayList<Map>();
+        List<Map<String, Object>> actions = new ArrayList<Map<String, Object>>();
         for (Cell cell : edit.getCells()) {
           // add atomic operation to txn
-          Map<String, Object> op = new HashMap<String, Object>(toStringMap(cell));
-          if (outputValues) op.put("value", Bytes.toStringBinary(cell.getValue()));
+          Map<String, Object> op = new HashMap<>(toStringMap(cell));
+          if (outputValues) {
+            op.put("value", Bytes.toStringBinary(CellUtil.cloneValue(cell)));
+          }
           // check row output filter
           if (row == null || ((String) op.get("row")).equals(row)) {
             actions.add(op);
@@ -305,29 +337,33 @@ public class WALPrettyPrinter {
           op.put("total_size_sum", CellUtil.estimatedHeapSizeOf(cell));
 
         }
-        if (actions.size() == 0)
+        if (actions.isEmpty()) {
           continue;
+        }
         txn.put("actions", actions);
         if (outputJSON) {
           // JSON output is a straightforward "toString" on the txn object
-          if (firstTxn)
+          if (firstTxn) {
             firstTxn = false;
-          else
+          } else {
             out.print(",");
+          }
           // encode and print JSON
           out.print(GSON.toJson(txn));
         } else {
           // Pretty output, complete with indentation by atomic action
-          out.println("Sequence=" + txn.get("sequence") + " "
-              + ", region=" + txn.get("region") + " at write timestamp=" + new Date(writeTime));
+          out.println(String.format(outputTmpl,
+              txn.get("sequence"), txn.get("table"), txn.get("region"), new Date(writeTime)));
           for (int i = 0; i < actions.size(); i++) {
-            Map op = actions.get(i);
+            Map<String, Object> op = actions.get(i);
             out.println("row=" + op.get("row") +
                 ", column=" + op.get("family") + ":" + op.get("qualifier"));
             if (op.get("tag") != null) {
               out.println("    tag: " + op.get("tag"));
             }
-            if (outputValues) out.println("    value: " + op.get("value"));
+            if (outputValues) {
+              out.println("    value: " + op.get("value"));
+            }
             out.println("cell total size sum: " + op.get("total_size_sum"));
           }
         }
@@ -386,6 +422,7 @@ public class WALPrettyPrinter {
     options.addOption("h", "help", false, "Output help message");
     options.addOption("j", "json", false, "Output JSON");
     options.addOption("p", "printvals", false, "Print values");
+    options.addOption("t", "table", true, "Table name to filter by.");
     options.addOption("r", "region", true,
         "Region to filter by. Pass encoded region name; e.g. '9192caead6a5a20acb4454ffbc79fa14'");
     options.addOption("s", "sequence", true,
@@ -405,21 +442,29 @@ public class WALPrettyPrinter {
         System.exit(-1);
       }
       // configure the pretty printer using command line options
-      if (cmd.hasOption("p"))
+      if (cmd.hasOption("p")) {
         printer.enableValues();
-      if (cmd.hasOption("j"))
+      }
+      if (cmd.hasOption("j")) {
         printer.enableJSON();
-      if (cmd.hasOption("r"))
+      }
+      if (cmd.hasOption("t")) {
+        printer.setTableFilter(cmd.getOptionValue("t"));
+      }
+      if (cmd.hasOption("r")) {
         printer.setRegionFilter(cmd.getOptionValue("r"));
-      if (cmd.hasOption("s"))
+      }
+      if (cmd.hasOption("s")) {
         printer.setSequenceFilter(Long.parseLong(cmd.getOptionValue("s")));
-      if (cmd.hasOption("w"))
+      }
+      if (cmd.hasOption("w")) {
         printer.setRowFilter(cmd.getOptionValue("w"));
+      }
       if (cmd.hasOption("g")) {
         printer.setPosition(Long.parseLong(cmd.getOptionValue("g")));
       }
     } catch (ParseException e) {
-      e.printStackTrace();
+      LOG.error("Failed to parse commandLine arguments", e);
       HelpFormatter formatter = new HelpFormatter();
       formatter.printHelp("HFile filename(s) ", options, true);
       System.exit(-1);