diff --git i/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java w/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java index b960443..7165015 100644 --- i/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java +++ w/src/main/java/org/apache/hadoop/hbase/io/hfile/HFile.java @@ -1764,12 +1764,12 @@ public class HFile { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("size=" + count); + sb.append("size=" + count).append("\n"); for (int i = 0; i < count ; i++) { - sb.append(", "); - sb.append("key=").append(Bytes.toStringBinary(blockKeys[i])). - append(", offset=").append(blockOffsets[i]). - append(", dataSize=" + blockDataSizes[i]); + sb.append("key=").append(KeyValue.keyToString(blockKeys[i])). + append("\n offset=").append(blockOffsets[i]). + append(", dataSize=" + blockDataSizes[i]). + append("\n"); } return sb.toString(); } @@ -1890,7 +1890,9 @@ public class HFile { Options options = new Options(); options.addOption("v", "verbose", false, "Verbose output; emits file and meta data delimiters"); options.addOption("p", "printkv", false, "Print key/value pairs"); + options.addOption("e", "printkey", false, "Print keys"); options.addOption("m", "printmeta", false, "Print meta data of file"); + options.addOption("b", "printblocks", false, "Print block index meta data"); options.addOption("k", "checkrow", false, "Enable row order check; looks for out-of-order keys"); options.addOption("a", "checkfamily", false, "Enable family check"); @@ -1906,8 +1908,10 @@ public class HFile { CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); boolean verbose = cmd.hasOption("v"); - boolean printKeyValue = cmd.hasOption("p"); + boolean printValue = cmd.hasOption("p"); + boolean printKey = cmd.hasOption("e") || printValue; boolean printMeta = cmd.hasOption("m"); + boolean printBlocks = cmd.hasOption("b"); boolean checkRow = cmd.hasOption("k"); boolean checkFamily = cmd.hasOption("a"); // get configuration, file system and get list of files @@ -1916,7 +1920,6 @@ public class HFile { conf.get(org.apache.hadoop.hbase.HConstants.HBASE_DIR)); conf.set("fs.default.name", conf.get(org.apache.hadoop.hbase.HConstants.HBASE_DIR)); - FileSystem fs = FileSystem.get(conf); ArrayList files = new ArrayList(); if (cmd.hasOption("f")) { files.add(new Path(cmd.getOptionValue("f"))); @@ -1930,7 +1933,8 @@ public class HFile { String enc = HRegionInfo.encodeRegionName(rn); Path regionDir = new Path(tableDir, enc); if (verbose) System.out.println("region dir -> " + regionDir); - List regionFiles = getStoreFiles(fs, regionDir); + List regionFiles = + getStoreFiles(FileSystem.get(conf), regionDir); if (verbose) System.out.println("Number of region files found -> " + regionFiles.size()); if (verbose) { @@ -1944,6 +1948,7 @@ public class HFile { // iterate over all files found for (Path file : files) { if (verbose) System.out.println("Scanning -> " + file); + FileSystem fs = file.getFileSystem(conf); if (!fs.exists(file)) { System.err.println("ERROR, file doesnt exist: " + file); continue; @@ -1952,7 +1957,7 @@ public class HFile { HFile.Reader reader = new HFile.Reader(fs, file, null, false, false); Map fileInfo = reader.loadFileInfo(); int count = 0; - if (verbose || printKeyValue || checkRow || checkFamily) { + if (verbose || printKey || checkRow || checkFamily) { // scan over file and read key/value's and check if requested HFileScanner scanner = reader.getScanner(false, false); scanner.seekTo(); @@ -1960,9 +1965,12 @@ public class HFile { do { KeyValue kv = scanner.getKeyValue(); // dump key value - if (printKeyValue) { - System.out.println("K: " + kv + - " V: " + Bytes.toStringBinary(kv.getValue())); + if (printKey) { + System.out.print("K: " + kv); + if (printValue) { + System.out.print(" V: " + Bytes.toStringBinary(kv.getValue())); + } + System.out.println(); } // check if rows are in order if (checkRow && pkv != null) { @@ -1992,7 +2000,7 @@ public class HFile { count++; } while (scanner.next()); } - if (verbose || printKeyValue) { + if (verbose || printKey) { System.out.println("Scanned kv count -> " + count); } // print meta data @@ -2033,6 +2041,10 @@ public class HFile { System.out.println("Could not get bloom data from meta block"); } } + if (printBlocks) { + System.out.println("Block Index:"); + System.out.println(reader.blockIndex); + } reader.close(); } } catch (Exception e) {