Skip to content

Commit

Permalink
HBASE-23847 Removed deprecated setStartRow from Scan (apache#1220)
Browse files Browse the repository at this point in the history
Signed-off-by: Viraj Jasani <[email protected]>
  • Loading branch information
HorizonNet authored and thangTang committed Apr 16, 2020
1 parent d24bf74 commit 3048658
Show file tree
Hide file tree
Showing 29 changed files with 56 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ private Scan createScanForBackupHistory() {
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);
Expand Down Expand Up @@ -1541,7 +1541,7 @@ private Scan createScanForReadLogTimestampMap(String backupRoot) {
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);

Expand Down Expand Up @@ -1582,7 +1582,7 @@ private Scan createScanForReadRegionServerLastLogRollResult(String backupRoot) {
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);
Expand Down Expand Up @@ -1891,7 +1891,7 @@ static Scan createScanForBulkLoadedFiles(String backupId) {
: 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);
Expand Down Expand Up @@ -1939,7 +1939,7 @@ private Scan createScanForGetWALs(String backupRoot) {
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;
Expand All @@ -1966,7 +1966,7 @@ private Scan createScanForBackupSetList() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public static Scan getScanForTableName(Connection connection, TableName tableNam
byte[] stopKey = getTableStopRowForMeta(tableName, QueryType.REGION);

Scan scan = getMetaScan(connection, -1);
scan.setStartRow(startKey);
scan.withStartRow(startKey);
scan.setStopRow(stopKey);
return scan;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public Scan() {}
*/
@Deprecated
public Scan(byte[] startRow) {
setStartRow(startRow);
withStartRow(startRow);
}

/**
Expand All @@ -205,7 +205,7 @@ public Scan(byte[] startRow) {
*/
@Deprecated
public Scan(byte[] startRow, byte[] stopRow) {
setStartRow(startRow);
withStartRow(startRow);
setStopRow(stopRow);
}

Expand Down Expand Up @@ -394,31 +394,6 @@ public Scan setTimestamp(long timestamp) {
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>
Expand Down Expand Up @@ -526,17 +501,17 @@ public Scan withStopRow(byte[] stopRow, boolean inclusive) {
* <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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ public void testSetAuthorizations() {
@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ R median(final Table table, ColumnInterpreter<R, S, P, Q, T> ci, Scan scan) thro
Scan scan2 = new Scan(scan);
// inherit stop row from method parameter
if (startRow != null) {
scan2.setStartRow(startRow);
scan2.withStartRow(startRow);
}
ResultScanner scanner = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ private Scan validateKey(final RegionInfo region, final ExportProtos.ExportReque
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ public int run(String[] args) throws Exception {
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")));
Expand Down Expand Up @@ -1711,7 +1711,7 @@ public int run(String[] args) throws Exception {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void run() {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static Scan getScanFromCommandLine(Configuration conf, String[] args) throws IOE
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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Scan initScan() throws IOException {
scan.setMaxVersions(versions);
}
if (!isTableStartRow(startRow)) {
scan.setStartRow(startRow);
scan.withStartRow(startRow);
}
if (!isTableEndRow(stopRow)) {
scan.setStopRow(stopRow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
* 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public RecordReader<ImmutableBytesWritable, Result> createRecordReader(

try {
Scan sc = tSplit.getScan();
sc.setStartRow(tSplit.getStartRow());
sc.withStartRow(tSplit.getStartRow());
sc.setStopRow(tSplit.getEndRow());
trr.setScan(sc);
trr.setTable(table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static void setScanFilter(Scan scan, List<MultiRowRangeFilter.RowRange>
}
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private static String toHex(ImmutableBytesWritable bytes) {
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);
Expand Down Expand Up @@ -681,7 +681,7 @@ private void finishRemainingHashRanges(Context context) throws IOException,
// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static Scan createScanFromConfiguration(Configuration conf) throws IOExce
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public RecordReader<ImmutableBytesWritable, Result> createRecordReader(
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void map(ImmutableBytesWritable row, final Result value,
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) {
Expand Down Expand Up @@ -511,7 +511,7 @@ private static void setRowPrefixFilter(Scan scan, String rowPrefixes) {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private void testScan(String start, String stop, String last)
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void runTestMapreduce(Table table) throws IOException,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public TableScanResource getScanResource(
byte[] prefixBytes = Bytes.toBytes(prefix);
prefixFilter = new PrefixFilter(Bytes.toBytes(prefix));
if (startRow.isEmpty()) {
tableScan.setStartRow(prefixBytes);
tableScan.withStartRow(prefixBytes);
}
}
if (LOG.isTraceEnabled()) {
Expand All @@ -154,7 +154,7 @@ public TableScanResource getScanResource(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ public void testJira6912() throws Exception {
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,
Expand Down Expand Up @@ -2114,7 +2114,7 @@ private void reverseScanTest(Table table, boolean small) throws IOException {
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;
Expand All @@ -2135,7 +2135,7 @@ private void reverseScanTest(Table table, boolean small) throws IOException {
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;
Expand All @@ -2157,7 +2157,7 @@ private void reverseScanTest(Table table, boolean small) throws IOException {
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;
Expand All @@ -2178,7 +2178,7 @@ private void reverseScanTest(Table table, boolean small) throws IOException {
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;
Expand All @@ -2199,7 +2199,7 @@ private void reverseScanTest(Table table, boolean small) throws IOException {
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;
Expand Down
Loading

0 comments on commit 3048658

Please sign in to comment.