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 GitHub
parent 0dae377f53
commit 8f4c255b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -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 {

View File

@ -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);