You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by vj...@apache.org on 2020/10/04 10:53:39 UTC
[hbase] branch branch-2.2 updated: HBASE-25115 HFilePrettyPrinter
can't seek to the row which is the first row of a hfile (#2481)
This is an automated email from the ASF dual-hosted git repository.
vjasani pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.2 by this push:
new 7de2bb2 HBASE-25115 HFilePrettyPrinter can't seek to the row which is the first row of a hfile (#2481)
7de2bb2 is described below
commit 7de2bb22ba000a7fb430386693902fd78dbe3dd0
Author: zhongchaoqiang <zh...@huawei.com>
AuthorDate: Sun Oct 4 16:02:12 2020 +0530
HBASE-25115 HFilePrettyPrinter can't seek to the row which is the first row of a hfile (#2481)
Closes #2473
Signed-off-by: stack <st...@apache.org>
Signed-off-by: Wellington Chevreuil <wc...@apache.org>
Signed-off-by: Viraj Jasani <vj...@apache.org>
---
.../hadoop/hbase/io/hfile/HFilePrettyPrinter.java | 10 +++++-----
.../hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java | 19 +++++++++++++++++++
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
index 98154f9..53dcc45 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java
@@ -323,16 +323,16 @@ public class HFilePrettyPrinter extends Configured implements Tool {
// scan over file and read key/value's and check if requested
HFileScanner scanner = reader.getScanner(false, false, false);
fileStats = new KeyValueStatsCollector();
- boolean shouldScanKeysValues = false;
- if (this.isSeekToRow) {
+ boolean shouldScanKeysValues;
+ if (this.isSeekToRow && !Bytes.equals(row, reader.getFirstRowKey().orElse(null))) {
// seek to the first kv on this row
- shouldScanKeysValues =
- (scanner.seekTo(PrivateCellUtil.createFirstOnRow(this.row)) != -1);
+ shouldScanKeysValues = (scanner.seekTo(PrivateCellUtil.createFirstOnRow(this.row)) != -1);
} else {
shouldScanKeysValues = scanner.seekTo();
}
- if (shouldScanKeysValues)
+ if (shouldScanKeysValues) {
scanKeysValues(file, fileStats, scanner, row);
+ }
}
// print meta data
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java
index e0a168e..cb149c1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFilePrettyPrinter.java
@@ -107,4 +107,23 @@ public class TestHFilePrettyPrinter {
String expectedResult = "Scanning -> " + fileInRootDir + "\n" + "Scanned kv count -> 1000\n";
assertEquals(expectedResult, result);
}
+
+ @Test
+ public void testHFilePrettyPrinterSeekFirstRow() throws Exception {
+ Path fileNotInRootDir = UTIL.getDataTestDir("hfile");
+ TestHRegionServerBulkLoad.createHFile(fs, fileNotInRootDir, cf, fam, value, 1000);
+ assertNotEquals("directory used is not an HBase root dir", UTIL.getDefaultRootDirPath(),
+ fileNotInRootDir);
+
+ HFile.Reader reader =
+ HFile.createReader(fs, fileNotInRootDir, CacheConfig.DISABLED, true, conf);
+ String firstRowKey = new String(reader.getFirstRowKey().get());
+
+ System.setOut(ps);
+ new HFilePrettyPrinter(conf)
+ .run(new String[] { "-v", "-w" + firstRowKey, String.valueOf(fileNotInRootDir) });
+ String result = new String(stream.toByteArray());
+ String expectedResult = "Scanning -> " + fileNotInRootDir + "\n" + "Scanned kv count -> 1\n";
+ assertEquals(expectedResult, result);
+ }
}