HBASE-23847 Removed deprecated setStartRow from Scan (#1220)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Jan Hentschel 2020-03-13 01:43:17 +01:00 committed by GitHub
parent e5b0455c38
commit 1b163d98b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 56 additions and 81 deletions

View File

@ -1501,7 +1501,7 @@ public final class BackupSystemTable implements Closeable {
byte[] startRow = Bytes.toBytes(BACKUP_INFO_PREFIX);
byte[] stopRow = Arrays.copyOf(startRow, startRow.length);
stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1);
scan.setStartRow(startRow);
scan.withStartRow(startRow);
scan.setStopRow(stopRow);
scan.addFamily(BackupSystemTable.SESSIONS_FAMILY);
scan.setMaxVersions(1);
@ -1541,7 +1541,7 @@ public final class BackupSystemTable implements Closeable {
byte[] startRow = rowkey(TABLE_RS_LOG_MAP_PREFIX, backupRoot);
byte[] stopRow = Arrays.copyOf(startRow, startRow.length);
stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1);
scan.setStartRow(startRow);
scan.withStartRow(startRow);
scan.setStopRow(stopRow);
scan.addFamily(BackupSystemTable.META_FAMILY);
@ -1582,7 +1582,7 @@ public final class BackupSystemTable implements Closeable {
byte[] startRow = rowkey(RS_LOG_TS_PREFIX, backupRoot);
byte[] stopRow = Arrays.copyOf(startRow, startRow.length);
stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1);
scan.setStartRow(startRow);
scan.withStartRow(startRow);
scan.setStopRow(stopRow);
scan.addFamily(BackupSystemTable.META_FAMILY);
scan.setMaxVersions(1);
@ -1891,7 +1891,7 @@ public final class BackupSystemTable implements Closeable {
: rowkey(BULK_LOAD_PREFIX, backupId + BLK_LD_DELIM);
byte[] stopRow = Arrays.copyOf(startRow, startRow.length);
stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1);
scan.setStartRow(startRow);
scan.withStartRow(startRow);
scan.setStopRow(stopRow);
scan.addFamily(BackupSystemTable.META_FAMILY);
scan.setMaxVersions(1);
@ -1939,7 +1939,7 @@ public final class BackupSystemTable implements Closeable {
byte[] startRow = Bytes.toBytes(WALS_PREFIX);
byte[] stopRow = Arrays.copyOf(startRow, startRow.length);
stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1);
scan.setStartRow(startRow);
scan.withStartRow(startRow);
scan.setStopRow(stopRow);
scan.addFamily(BackupSystemTable.META_FAMILY);
return scan;
@ -1966,7 +1966,7 @@ public final class BackupSystemTable implements Closeable {
byte[] startRow = Bytes.toBytes(SET_KEY_PREFIX);
byte[] stopRow = Arrays.copyOf(startRow, startRow.length);
stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1);
scan.setStartRow(startRow);
scan.withStartRow(startRow);
scan.setStopRow(stopRow);
scan.addFamily(BackupSystemTable.META_FAMILY);
return scan;

View File

@ -575,7 +575,7 @@ public class MetaTableAccessor {
byte[] stopKey = getTableStopRowForMeta(tableName, QueryType.REGION);
Scan scan = getMetaScan(connection, -1);
scan.setStartRow(startKey);
scan.withStartRow(startKey);
scan.setStopRow(stopKey);
return scan;
}

View File

@ -192,7 +192,7 @@ public class Scan extends Query {
*/
@Deprecated
public Scan(byte[] startRow) {
setStartRow(startRow);
withStartRow(startRow);
}
/**
@ -205,7 +205,7 @@ public class Scan extends Query {
*/
@Deprecated
public Scan(byte[] startRow, byte[] stopRow) {
setStartRow(startRow);
withStartRow(startRow);
setStopRow(stopRow);
}
@ -394,31 +394,6 @@ public class Scan extends Query {
return (Scan) super.setColumnFamilyTimeRange(cf, minStamp, maxStamp);
}
/**
* Set the start row of the scan.
* <p>
* If the specified row does not exist, the Scanner will start from the next closest row after the
* specified row.
* @param startRow row to start scanner at or after
* @return this
* @throws IllegalArgumentException if startRow does not meet criteria for a row key (when length
* exceeds {@link HConstants#MAX_ROW_LENGTH})
* @deprecated since 2.0.0 and will be removed in 3.0.0. Use {@link #withStartRow(byte[])}
* instead. This method may change the inclusive of the stop row to keep compatible with the old
* behavior.
* @see #withStartRow(byte[])
* @see <a href="https://issues.apache.org/jira/browse/HBASE-17320">HBASE-17320</a>
*/
@Deprecated
public Scan setStartRow(byte[] startRow) {
withStartRow(startRow);
if (ClientUtil.areScanStartRowAndStopRowEqual(this.startRow, this.stopRow)) {
// for keeping the old behavior that a scan with the same start and stop row is a get scan.
this.includeStopRow = true;
}
return this;
}
/**
* Set the start row of the scan.
* <p>
@ -526,17 +501,17 @@ public class Scan extends Query {
* <p>This is a utility method that converts the desired rowPrefix into the appropriate values
* for the startRow and stopRow to achieve the desired result.</p>
* <p>This can safely be used in combination with setFilter.</p>
* <p><b>NOTE: Doing a {@link #setStartRow(byte[])} and/or {@link #setStopRow(byte[])}
* <p><b>NOTE: Doing a {@link #withStartRow(byte[])} and/or {@link #setStopRow(byte[])}
* after this method will yield undefined results.</b></p>
* @param rowPrefix the prefix all rows must start with. (Set <i>null</i> to remove the filter.)
* @return this
*/
public Scan setRowPrefixFilter(byte[] rowPrefix) {
if (rowPrefix == null) {
setStartRow(HConstants.EMPTY_START_ROW);
withStartRow(HConstants.EMPTY_START_ROW);
setStopRow(HConstants.EMPTY_END_ROW);
} else {
this.setStartRow(rowPrefix);
this.withStartRow(rowPrefix);
this.setStopRow(ClientUtil.calculateTheClosestNextRowKeyForPrefix(rowPrefix));
}
return this;

View File

@ -194,11 +194,11 @@ public class TestScan {
@Test
public void testSetStartRowAndSetStopRow() {
Scan scan = new Scan();
scan.setStartRow(null);
scan.setStartRow(new byte[1]);
scan.setStartRow(new byte[HConstants.MAX_ROW_LENGTH]);
scan.withStartRow(null);
scan.withStartRow(new byte[1]);
scan.withStartRow(new byte[HConstants.MAX_ROW_LENGTH]);
try {
scan.setStartRow(new byte[HConstants.MAX_ROW_LENGTH+1]);
scan.withStartRow(new byte[HConstants.MAX_ROW_LENGTH+1]);
fail("should've thrown exception");
} catch (IllegalArgumentException iae) {
} catch (Exception e) {

View File

@ -799,7 +799,7 @@ public class AggregationClient implements Closeable {
Scan scan2 = new Scan(scan);
// inherit stop row from method parameter
if (startRow != null) {
scan2.setStartRow(startRow);
scan2.withStartRow(startRow);
}
ResultScanner scanner = null;
try {

View File

@ -361,13 +361,13 @@ public class Export extends ExportProtos.ExportService implements RegionCoproces
byte[] originStartKey = scan.getStartRow();
if (originStartKey == null
|| Bytes.compareTo(originStartKey, regionStartKey) < 0) {
scan.setStartRow(regionStartKey);
scan.withStartRow(regionStartKey);
}
byte[] regionEndKey = region.getEndKey();
byte[] originEndKey = scan.getStopRow();
if (originEndKey == null
|| Bytes.compareTo(originEndKey, regionEndKey) > 0) {
scan.setStartRow(regionEndKey);
scan.withStartRow(regionEndKey);
}
return scan;
}

View File

@ -1653,7 +1653,7 @@ public class IntegrationTestBigLinkedList extends IntegrationTestBase {
scan.setBatch(10000);
if (cmd.hasOption("s"))
scan.setStartRow(Bytes.toBytesBinary(cmd.getOptionValue("s")));
scan.withStartRow(Bytes.toBytesBinary(cmd.getOptionValue("s")));
if (cmd.hasOption("e"))
scan.setStopRow(Bytes.toBytesBinary(cmd.getOptionValue("e")));
@ -1711,7 +1711,7 @@ public class IntegrationTestBigLinkedList extends IntegrationTestBase {
abstract static class WalkerBase extends Configured{
protected static CINode findStartNode(Table table, byte[] startKey) throws IOException {
Scan scan = new Scan();
scan.setStartRow(startKey);
scan.withStartRow(startKey);
scan.setBatch(1);
scan.addColumn(FAMILY_NAME, COLUMN_PREV);

View File

@ -125,7 +125,7 @@ public class IntegrationTestSendTraceRequests extends AbstractHBaseTool {
try (TraceScope scope = TraceUtil.createTrace("Scan")){
Table ht = util.getConnection().getTable(tableName);
Scan s = new Scan();
s.setStartRow(Bytes.toBytes(rowKeyQueue.take()));
s.withStartRow(Bytes.toBytes(rowKeyQueue.take()));
s.setBatch(7);
rs = ht.getScanner(s);
// Something to keep the jvm from removing the loop.

View File

@ -121,7 +121,7 @@ public final class ExportUtils {
s.setCacheBlocks(false);
// set Start and Stop row
if (conf.get(TableInputFormat.SCAN_ROW_START) != null) {
s.setStartRow(Bytes.toBytesBinary(conf.get(TableInputFormat.SCAN_ROW_START)));
s.withStartRow(Bytes.toBytesBinary(conf.get(TableInputFormat.SCAN_ROW_START)));
}
if (conf.get(TableInputFormat.SCAN_ROW_STOP) != null) {
s.setStopRow(Bytes.toBytesBinary(conf.get(TableInputFormat.SCAN_ROW_STOP)));

View File

@ -195,7 +195,7 @@ public class HashTable extends Configured implements Tool {
scan.setMaxVersions(versions);
}
if (!isTableStartRow(startRow)) {
scan.setStartRow(startRow);
scan.withStartRow(startRow);
}
if (!isTableEndRow(stopRow)) {
scan.setStopRow(stopRow);

View File

@ -38,13 +38,13 @@ import org.apache.hadoop.hbase.client.Scan;
* List&lt;Scan&gt; scans = new ArrayList&lt;Scan&gt;();
*
* Scan scan1 = new Scan();
* scan1.setStartRow(firstRow1);
* scan1.withStartRow(firstRow1);
* scan1.setStopRow(lastRow1);
* scan1.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, table1);
* scans.add(scan1);
*
* Scan scan2 = new Scan();
* scan2.setStartRow(firstRow2);
* scan2.withStartRow(firstRow2);
* scan2.setStopRow(lastRow2);
* scan1.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, table2);
* scans.add(scan2);

View File

@ -98,7 +98,7 @@ public abstract class MultiTableInputFormatBase extends
try {
Scan sc = tSplit.getScan();
sc.setStartRow(tSplit.getStartRow());
sc.withStartRow(tSplit.getStartRow());
sc.setStopRow(tSplit.getEndRow());
trr.setScan(sc);
trr.setTable(table);

View File

@ -171,7 +171,7 @@ public class RowCounter extends AbstractHBaseTool {
}
if (size == 1) {
MultiRowRangeFilter.RowRange range = rowRangeList.get(0);
scan.setStartRow(range.getStartRow()); //inclusive
scan.withStartRow(range.getStartRow()); //inclusive
scan.setStopRow(range.getStopRow()); //exclusive
} else if (size > 1) {
scan.setFilter(new MultiRowRangeFilter(rowRangeList));

View File

@ -340,7 +340,7 @@ public class SyncTable extends Configured implements Tool {
private void syncRange(Context context, ImmutableBytesWritable startRow,
ImmutableBytesWritable stopRow) throws IOException, InterruptedException {
Scan scan = sourceTableHash.initScan();
scan.setStartRow(startRow.copyBytes());
scan.withStartRow(startRow.copyBytes());
scan.setStopRow(stopRow.copyBytes());
ResultScanner sourceScanner = sourceTable.getScanner(scan);
@ -681,7 +681,7 @@ public class SyncTable extends Configured implements Tool {
// the open hash range continues past the end of this region
// add a scan to complete the current hash range
Scan scan = sourceTableHash.initScan();
scan.setStartRow(splitEndRow);
scan.withStartRow(splitEndRow);
if (nextSourceKey == null) {
scan.setStopRow(sourceTableHash.stopRow);
} else {

View File

@ -148,7 +148,7 @@ implements Configurable {
Scan scan = new Scan();
if (conf.get(SCAN_ROW_START) != null) {
scan.setStartRow(Bytes.toBytesBinary(conf.get(SCAN_ROW_START)));
scan.withStartRow(Bytes.toBytesBinary(conf.get(SCAN_ROW_START)));
}
if (conf.get(SCAN_ROW_STOP) != null) {

View File

@ -181,7 +181,7 @@ public abstract class TableInputFormatBase
final TableRecordReader trr =
this.tableRecordReader != null ? this.tableRecordReader : new TableRecordReader();
Scan sc = new Scan(this.scan);
sc.setStartRow(tSplit.getStartRow());
sc.withStartRow(tSplit.getStartRow());
sc.setStopRow(tSplit.getEndRow());
trr.setScan(sc);
trr.setTable(getTable());

View File

@ -198,7 +198,7 @@ public class VerifyReplication extends Configured implements Tool {
TableName peerTableName = TableName.valueOf(peerName);
replicatedConnection = ConnectionFactory.createConnection(peerConf);
replicatedTable = replicatedConnection.getTable(peerTableName);
scan.setStartRow(value.getRow());
scan.withStartRow(value.getRow());
byte[] endRow = null;
if (tableSplit instanceof TableSnapshotInputFormat.TableSnapshotRegionSplit) {
@ -511,7 +511,7 @@ public class VerifyReplication extends Configured implements Tool {
}
private static void setStartAndStopRows(Scan scan, byte[] startPrefixRow, byte[] lastPrefixRow) {
scan.setStartRow(startPrefixRow);
scan.withStartRow(startPrefixRow);
byte[] stopRow = Bytes.add(Bytes.head(lastPrefixRow, lastPrefixRow.length - 1),
new byte[]{(byte) (lastPrefixRow[lastPrefixRow.length - 1] + 1)});
scan.setStopRow(stopRow);

View File

@ -238,7 +238,7 @@ public abstract class MultiTableInputFormatTestBase {
scan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(tableName));
if (start != null) {
scan.setStartRow(Bytes.toBytes(start));
scan.withStartRow(Bytes.toBytes(start));
}
if (stop != null) {
scan.setStopRow(Bytes.toBytes(stop));

View File

@ -169,7 +169,7 @@ public class TestTableInputFormat {
org.apache.hadoop.hbase.mapreduce.TableRecordReaderImpl trr =
new org.apache.hadoop.hbase.mapreduce.TableRecordReaderImpl();
Scan s = new Scan();
s.setStartRow(Bytes.toBytes("aaa"));
s.withStartRow(Bytes.toBytes("aaa"));
s.setStopRow(Bytes.toBytes("zzz"));
s.addFamily(FAMILY);
trr.setScan(s);

View File

@ -140,7 +140,7 @@ public class TableResource extends ResourceBase {
byte[] prefixBytes = Bytes.toBytes(prefix);
prefixFilter = new PrefixFilter(Bytes.toBytes(prefix));
if (startRow.isEmpty()) {
tableScan.setStartRow(prefixBytes);
tableScan.withStartRow(prefixBytes);
}
}
if (LOG.isTraceEnabled()) {
@ -154,7 +154,7 @@ public class TableResource extends ResourceBase {
tableScan.setMaxVersions(maxVersions);
tableScan.setTimeRange(startTime, endTime);
if (!startRow.isEmpty()) {
tableScan.setStartRow(Bytes.toBytes(startRow));
tableScan.withStartRow(Bytes.toBytes(startRow));
}
tableScan.setStopRow(Bytes.toBytes(endRow));
for (String col : column) {

View File

@ -1317,7 +1317,7 @@ public class TestFromClientSide5 extends FromClientSideBase {
TEST_UTIL.flush();
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes(1));
scan.withStartRow(Bytes.toBytes(1));
scan.setStopRow(Bytes.toBytes(3));
scan.addColumn(FAMILY, FAMILY);
scan.setFilter(new RowFilter(CompareOperator.NOT_EQUAL,
@ -2114,7 +2114,7 @@ public class TestFromClientSide5 extends FromClientSideBase {
scan = new Scan();
scan.setSmall(small);
scan.setReversed(true);
scan.setStartRow(Bytes.toBytes("002"));
scan.withStartRow(Bytes.toBytes("002"));
try (ResultScanner scanner = table.getScanner(scan)) {
int count = 0;
byte[] lastRow = null;
@ -2135,7 +2135,7 @@ public class TestFromClientSide5 extends FromClientSideBase {
scan = new Scan();
scan.setSmall(small);
scan.setReversed(true);
scan.setStartRow(Bytes.toBytes("002"));
scan.withStartRow(Bytes.toBytes("002"));
scan.setStopRow(Bytes.toBytes("000"));
try (ResultScanner scanner = table.getScanner(scan)) {
int count = 0;
@ -2157,7 +2157,7 @@ public class TestFromClientSide5 extends FromClientSideBase {
scan = new Scan();
scan.setSmall(small);
scan.setReversed(true);
scan.setStartRow(Bytes.toBytes("001"));
scan.withStartRow(Bytes.toBytes("001"));
try (ResultScanner scanner = table.getScanner(scan)) {
int count = 0;
byte[] lastRow = null;
@ -2178,7 +2178,7 @@ public class TestFromClientSide5 extends FromClientSideBase {
scan = new Scan();
scan.setSmall(small);
scan.setReversed(true);
scan.setStartRow(Bytes.toBytes("000"));
scan.withStartRow(Bytes.toBytes("000"));
try (ResultScanner scanner = table.getScanner(scan)) {
int count = 0;
byte[] lastRow = null;
@ -2199,7 +2199,7 @@ public class TestFromClientSide5 extends FromClientSideBase {
scan = new Scan();
scan.setSmall(small);
scan.setReversed(true);
scan.setStartRow(Bytes.toBytes("006"));
scan.withStartRow(Bytes.toBytes("006"));
scan.setStopRow(Bytes.toBytes("002"));
try (ResultScanner scanner = table.getScanner(scan)) {
int count = 0;

View File

@ -289,7 +289,7 @@ public class TestFilter {
Scan s = new Scan();
// set a start row
s.setStartRow(ROWS_FOUR[1]);
s.withStartRow(ROWS_FOUR[1]);
RegionScanner scanner = region.getScanner(s);
// reseek to row three.

View File

@ -156,7 +156,7 @@ public class TestFilterListOrOperatorWithBlkCnt {
Scan scan = new Scan();
scan.setMaxVersions();
if(!Bytes.toString(startRow).isEmpty()) {
scan.setStartRow(startRow);
scan.withStartRow(startRow);
}
if(!Bytes.toString(stopRow).isEmpty()) {
scan.setStopRow(stopRow);

View File

@ -215,7 +215,7 @@ public class TestSeekOptimizations {
qualSet.add(qualStr);
}
scan.setMaxVersions(maxVersions);
scan.setStartRow(rowBytes(startRow));
scan.withStartRow(rowBytes(startRow));
// Adjust for the fact that for multi-row queries the end row is exclusive.
{

View File

@ -452,7 +452,7 @@ public class TestTags {
increment.setAttribute("visibility", Bytes.toBytes("tag2"));
table.increment(increment);
TestCoprocessorForTags.checkTagPresence = true;
scanner = table.getScanner(new Scan().setStartRow(row2));
scanner = table.getScanner(new Scan().withStartRow(row2));
result = scanner.next();
kv = KeyValueUtil.ensureKeyValue(result.getColumnLatestCell(f, q));
tags = TestCoprocessorForTags.tags;
@ -472,7 +472,7 @@ public class TestTags {
append.addColumn(f, q, Bytes.toBytes("b"));
table.append(append);
TestCoprocessorForTags.checkTagPresence = true;
scanner = table.getScanner(new Scan().setStartRow(row3));
scanner = table.getScanner(new Scan().withStartRow(row3));
result = scanner.next();
kv = KeyValueUtil.ensureKeyValue(result.getColumnLatestCell(f, q));
tags = TestCoprocessorForTags.tags;
@ -486,7 +486,7 @@ public class TestTags {
append.setAttribute("visibility", Bytes.toBytes("tag2"));
table.append(append);
TestCoprocessorForTags.checkTagPresence = true;
scanner = table.getScanner(new Scan().setStartRow(row3));
scanner = table.getScanner(new Scan().withStartRow(row3));
result = scanner.next();
kv = KeyValueUtil.ensureKeyValue(result.getColumnLatestCell(f, q));
tags = TestCoprocessorForTags.tags;
@ -510,7 +510,7 @@ public class TestTags {
append.setAttribute("visibility", Bytes.toBytes("tag2"));
table.append(append);
TestCoprocessorForTags.checkTagPresence = true;
scanner = table.getScanner(new Scan().setStartRow(row4));
scanner = table.getScanner(new Scan().withStartRow(row4));
result = scanner.next();
kv = KeyValueUtil.ensureKeyValue(result.getColumnLatestCell(f, q));
tags = TestCoprocessorForTags.tags;

View File

@ -241,7 +241,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override
public List<Cell> run() throws Exception {
Scan scan = new Scan();
scan.setStartRow(TEST_ROW);
scan.withStartRow(TEST_ROW);
scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } ));
scan.addFamily(TEST_FAMILY);
Connection connection = ConnectionFactory.createConnection(conf);

View File

@ -973,7 +973,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public List<Cell> run() throws Exception {
Scan scan = new Scan();
scan.setStartRow(TEST_ROW);
scan.withStartRow(TEST_ROW);
scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } ));
scan.addFamily(TEST_FAMILY);
Connection connection = ConnectionFactory.createConnection(conf);

View File

@ -883,7 +883,7 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements Hb
Scan scan = new Scan();
addAttributes(scan, attributes);
if (tScan.isSetStartRow()) {
scan.setStartRow(tScan.getStartRow());
scan.withStartRow(tScan.getStartRow());
}
if (tScan.isSetStopRow()) {
scan.setStopRow(tScan.getStopRow());
@ -1161,7 +1161,7 @@ public class ThriftHBaseServiceHandler extends HBaseServiceHandler implements Hb
Scan scan = new Scan(row);
scan.setReversed(true);
scan.addFamily(family);
scan.setStartRow(row);
scan.withStartRow(row);
try (Table table = getTable(tableName);
ResultScanner scanner = table.getScanner(scan)) {
return scanner.next();

View File

@ -513,7 +513,7 @@ public final class ThriftUtilities {
Scan out = new Scan();
if (in.isSetStartRow()) {
out.setStartRow(in.getStartRow());
out.withStartRow(in.getStartRow());
}
if (in.isSetStopRow()) {
out.setStopRow(in.getStopRow());