HBASE-24386 TableSnapshotScanner support scan limit (#1724)

Signed-off-by: Jan Hentschel <jan.hentschel@ultratendency.com>
Signed-off by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
niuyulin 2020-05-19 10:22:28 -05:00 committed by Viraj Jasani
parent fbe5e68251
commit 3235b568da
No known key found for this signature in database
GPG Key ID: 3AE697641452FC5D
2 changed files with 41 additions and 0 deletions

View File

@ -82,6 +82,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
@ -164,6 +165,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 {

View File

@ -40,6 +40,8 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.Rule;
import org.junit.rules.TestName;
@Category(LargeTests.class)
public class TestTableSnapshotScanner {
@ -54,6 +56,9 @@ public class TestTableSnapshotScanner {
private FileSystem fs;
private Path rootDir;
@Rule
public TestName name = new TestName();
public void setupCluster() throws Exception {
setupConf(UTIL.getConfiguration());
UTIL.startMiniCluster(NUM_REGION_SERVERS, true);
@ -159,6 +164,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.getHBaseAdmin().deleteSnapshot(snapshotName);
UTIL.deleteTable(tableName);
tearDownCluster();
}
}
@Test
public void testWithSingleRegion() throws Exception {
testScanner(UTIL, "testWithSingleRegion", 1, false);