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/05/19 15:23:30 UTC
[hbase] branch master updated: HBASE-24386 TableSnapshotScanner
support scan limit (#1724)
This is an automated email from the ASF dual-hosted git repository.
vjasani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new 8f4c255 HBASE-24386 TableSnapshotScanner support scan limit (#1724)
8f4c255 is described below
commit 8f4c255b386e892383ad4e001befece7fa922fd6
Author: niuyulin <ny...@163.com>
AuthorDate: Tue May 19 10:22:28 2020 -0500
HBASE-24386 TableSnapshotScanner support scan limit (#1724)
Signed-off-by: Jan Hentschel <ja...@ultratendency.com>
Signed-off by: Viraj Jasani <vj...@apache.org>
---
.../hadoop/hbase/client/TableSnapshotScanner.java | 4 +++
.../hbase/client/TestTableSnapshotScanner.java | 37 ++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/TableSnapshotScanner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/TableSnapshotScanner.java
index 295a2c7..146d76cc 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/TableSnapshotScanner.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/TableSnapshotScanner.java
@@ -83,6 +83,7 @@ public class TableSnapshotScanner extends AbstractClientScanner {
private ClientSideRegionScanner currentRegionScanner = null;
private int currentRegion = -1;
+ private int numOfCompleteRows = 0;
/**
* Creates a TableSnapshotScanner.
* @param conf the configuration
@@ -193,6 +194,9 @@ public class TableSnapshotScanner extends AbstractClientScanner {
try {
result = currentRegionScanner.next();
if (result != null) {
+ if (scan.getLimit() > 0 && ++this.numOfCompleteRows > scan.getLimit()) {
+ result = null;
+ }
return result;
}
} finally {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java
index d3e5150..1788421 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestTableSnapshotScanner.java
@@ -49,8 +49,10 @@ import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
import org.junit.After;
import org.junit.Assert;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -71,6 +73,9 @@ public class TestTableSnapshotScanner {
private FileSystem fs;
private Path rootDir;
+ @Rule
+ public TestName name = new TestName();
+
public static void blockUntilSplitFinished(HBaseTestingUtility util, TableName tableName,
int expectedRegionSize) throws Exception {
for (int i = 0; i < 100; i++) {
@@ -190,6 +195,38 @@ public class TestTableSnapshotScanner {
}
}
+
+ @Test
+ public void testScanLimit() throws Exception {
+ setupCluster();
+ final TableName tableName = TableName.valueOf(name.getMethodName());
+ final String snapshotName = tableName + "Snapshot";
+ TableSnapshotScanner scanner = null;
+ try {
+ createTableAndSnapshot(UTIL, tableName, snapshotName, 50);
+ Path restoreDir = UTIL.getDataTestDirOnTestFS(snapshotName);
+ Scan scan = new Scan().withStartRow(bbb).setLimit(100); // limit the scan
+
+ scanner = new TableSnapshotScanner(UTIL.getConfiguration(), restoreDir, snapshotName, scan);
+ int count = 0;
+ while (true) {
+ Result result = scanner.next();
+ if (result == null) {
+ break;
+ }
+ count++;
+ }
+ Assert.assertEquals(100, count);
+ } finally {
+ if (scanner != null) {
+ scanner.close();
+ }
+ UTIL.getAdmin().deleteSnapshot(snapshotName);
+ UTIL.deleteTable(tableName);
+ tearDownCluster();
+ }
+ }
+
@Test
public void testWithSingleRegion() throws Exception {
testScanner(UTIL, "testWithSingleRegion", 1, false);