From b2c46f2fea238bcb1895d37f9c1c162017c4724d Mon Sep 17 00:00:00 2001 From: wellington Date: Tue, 11 Sep 2018 18:23:17 +0100 Subject: [PATCH] HBASE-21185: Additional useful info to be printed by wal printer tool, for debugability purposes --- .../apache/hadoop/hbase/wal/WALPrettyPrinter.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 3fa496f..0cc3913 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 @@ -84,6 +84,8 @@ public class WALPrettyPrinter { private PrintStream out; // for JSON encoding private static final ObjectMapper MAPPER = new ObjectMapper(); + //allows for jumping straight to a given portion of the file + private long position; /** * Basic constructor that simply initializes values to reasonable defaults. @@ -202,6 +204,14 @@ public class WALPrettyPrinter { } /** + * sets the position to start seeking the WAL file + * @param position + */ + public void setPosition(long position) { + this.position = position; + } + + /** * enables output as a single, persistent list. at present, only relevant in * the case of JSON output. */ @@ -274,6 +284,10 @@ public class WALPrettyPrinter { firstTxn = true; } + if (position > 0) { + log.seek(position); + } + try { WAL.Entry entry; while ((entry = log.next()) != null) { @@ -297,6 +311,11 @@ public class WALPrettyPrinter { if (row == null || ((String) op.get("row")).equals(row)) { actions.add(op); } + op.put("total_size_sum", new Long(cell.getFamilyLength() + + cell.getQualifierLength() + + cell.getRowLength() + + cell.getTagsLength() + + cell.getValueLength())); } if (actions.isEmpty()) continue; @@ -321,8 +340,11 @@ public class WALPrettyPrinter { out.println(" tag: " + op.get("tag")); } if (outputValues) out.println(" value: " + op.get("value")); + out.println("cell total size sum: " + op.get("total_size_sum")); } } + out.println("edit heap size: " + entry.getEdit().heapSize()); + out.println("position: " + log.getPosition()); } } finally { log.close(); @@ -380,6 +402,7 @@ public class WALPrettyPrinter { options.addOption("s", "sequence", true, "Sequence to filter by. Pass sequence number."); options.addOption("w", "row", true, "Row to filter by. Pass row name."); + options.addOption("g", "goto", true, "Position to seek to in the file"); WALPrettyPrinter printer = new WALPrettyPrinter(); CommandLineParser parser = new PosixParser(); @@ -403,6 +426,8 @@ public class WALPrettyPrinter { printer.setSequenceFilter(Long.parseLong(cmd.getOptionValue("s"))); 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); HelpFormatter formatter = new HelpFormatter(); -- 2.10.1 (Apple Git-78)