You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2011/12/21 07:00:06 UTC
svn commit: r1221620 - in /hbase/trunk/src/main/java/org/apache/hadoop/hbase:
io/hfile/HFilePrettyPrinter.java regionserver/wal/HLogSplitter.java
Author: stack
Date: Wed Dec 21 06:00:05 2011
New Revision: 1221620
URL: http://svn.apache.org/viewvc?rev=1221620&view=rev
Log:
HBASE-4698 Let the HFile Pretty Printer print all the key values for a specific row
Modified:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java?rev=1221620&r1=1221619&r2=1221620&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java Wed Dec 21 06:00:05 2011
@@ -26,15 +26,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
@@ -67,7 +66,12 @@ public class HFilePrettyPrinter {
private boolean printStats;
private boolean checkRow;
private boolean checkFamily;
+ private boolean isSeekToRow = false;
+ /**
+ * 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>();
@@ -87,6 +91,8 @@ public class HFilePrettyPrinter {
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("w", "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'");
options.addOption("s", "stats", false, "Print statistics");
@@ -115,6 +121,17 @@ public class HFilePrettyPrinter {
files.add(new Path(cmd.getOptionValue("f")));
}
+ if (cmd.hasOption("w")) {
+ String key = cmd.getOptionValue("w");
+ if (key != null && key.length() != 0) {
+ row = key.getBytes();
+ isSeekToRow = true;
+ } else {
+ System.err.println("Invalid row is specified.");
+ System.exit(-1);
+ }
+ }
+
if (cmd.hasOption("r")) {
String regionName = cmd.getOptionValue("r");
byte[] rn = Bytes.toBytes(regionName);
@@ -198,8 +215,16 @@ public class HFilePrettyPrinter {
// scan over file and read key/value's and check if requested
HFileScanner scanner = reader.getScanner(false, false, false);
fileStats = new KeyValueStatsCollector();
- if (scanner.seekTo())
- scanKeysValues(file, fileStats, scanner);
+ boolean shouldScanKeysValues = false;
+ if (this.isSeekToRow) {
+ // seek to the first kv on this row
+ shouldScanKeysValues =
+ (scanner.seekTo(KeyValue.createFirstOnRow(this.row).getKey()) != -1);
+ } else {
+ shouldScanKeysValues = scanner.seekTo();
+ }
+ if (shouldScanKeysValues)
+ scanKeysValues(file, fileStats, scanner, row);
}
// print meta data
@@ -220,11 +245,19 @@ public class HFilePrettyPrinter {
reader.close();
}
- private void scanKeysValues(Path file, KeyValueStatsCollector fileStats, HFileScanner scanner)
- throws IOException {
+ private void scanKeysValues(Path file, KeyValueStatsCollector fileStats,
+ HFileScanner scanner, byte[] row) throws IOException {
KeyValue pkv = null;
do {
KeyValue kv = scanner.getKeyValue();
+ if (row != null && row.length != 0) {
+ int result = Bytes.compareTo(kv.getRow(), row);
+ if (result > 0) {
+ break;
+ } else if (result < 0) {
+ continue;
+ }
+ }
// collect stats
if (printStats) {
fileStats.collect(kv);
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java?rev=1221620&r1=1221619&r2=1221620&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogSplitter.java Wed Dec 21 06:00:05 2011
@@ -490,8 +490,8 @@ public class HLogSplitter {
}
String msg = "Processed " + editsCount + " edits across " + n + " regions" +
" threw away edits for " + (logWriters.size() - n) + " regions" +
- "; log file=" + logPath + " is corrupted = " + isCorrupted +
- " progress failed = " + progress_failed;
+ "; log file=" + logPath + " is corrupted=" + isCorrupted +
+ " progress failed=" + progress_failed;
LOG.info(msg);
status.markComplete(msg);
}