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:
parent
ce9051ea91
commit
61e2225151
|
@ -83,6 +83,7 @@ public class TableSnapshotScanner extends AbstractClientScanner {
|
||||||
private ClientSideRegionScanner currentRegionScanner = null;
|
private ClientSideRegionScanner currentRegionScanner = null;
|
||||||
private int currentRegion = -1;
|
private int currentRegion = -1;
|
||||||
|
|
||||||
|
private int numOfCompleteRows = 0;
|
||||||
/**
|
/**
|
||||||
* Creates a TableSnapshotScanner.
|
* Creates a TableSnapshotScanner.
|
||||||
* @param conf the configuration
|
* @param conf the configuration
|
||||||
|
@ -193,6 +194,9 @@ public class TableSnapshotScanner extends AbstractClientScanner {
|
||||||
try {
|
try {
|
||||||
result = currentRegionScanner.next();
|
result = currentRegionScanner.next();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
if (scan.getLimit() > 0 && ++this.numOfCompleteRows > scan.getLimit()) {
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -50,8 +50,10 @@ import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
import org.junit.rules.TestName;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -72,6 +74,9 @@ public class TestTableSnapshotScanner {
|
||||||
private FileSystem fs;
|
private FileSystem fs;
|
||||||
private Path rootDir;
|
private Path rootDir;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TestName name = new TestName();
|
||||||
|
|
||||||
public static void blockUntilSplitFinished(HBaseTestingUtility util, TableName tableName,
|
public static void blockUntilSplitFinished(HBaseTestingUtility util, TableName tableName,
|
||||||
int expectedRegionSize) throws Exception {
|
int expectedRegionSize) throws Exception {
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
|
@ -191,6 +196,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
|
@Test
|
||||||
public void testWithSingleRegion() throws Exception {
|
public void testWithSingleRegion() throws Exception {
|
||||||
testScanner(UTIL, "testWithSingleRegion", 1, false);
|
testScanner(UTIL, "testWithSingleRegion", 1, false);
|
||||||
|
|
Loading…
Reference in New Issue