@@ -176,7 +176,7 @@ private static Optional<TableState> getTableState(Result r) throws IOException {
176
176
* {@link CompletableFuture}.
177
177
*/
178
178
public static CompletableFuture <List <HRegionLocation >> getTableHRegionLocations (
179
- AsyncTable <AdvancedScanResultConsumer > metaTable , Optional < TableName > tableName ) {
179
+ AsyncTable <AdvancedScanResultConsumer > metaTable , TableName tableName ) {
180
180
CompletableFuture <List <HRegionLocation >> future = new CompletableFuture <>();
181
181
addListener (getTableRegionsAndLocations (metaTable , tableName , true ), (locations , err ) -> {
182
182
if (err != null ) {
@@ -202,37 +202,39 @@ public static CompletableFuture<List<HRegionLocation>> getTableHRegionLocations(
202
202
* {@link CompletableFuture}.
203
203
*/
204
204
private static CompletableFuture <List <Pair <RegionInfo , ServerName >>> getTableRegionsAndLocations (
205
- AsyncTable <AdvancedScanResultConsumer > metaTable , final Optional < TableName > tableName ,
206
- final boolean excludeOfflinedSplitParents ) {
205
+ final AsyncTable <AdvancedScanResultConsumer > metaTable ,
206
+ final TableName tableName , final boolean excludeOfflinedSplitParents ) {
207
207
CompletableFuture <List <Pair <RegionInfo , ServerName >>> future = new CompletableFuture <>();
208
- if (tableName . filter (( t ) -> t . equals ( TableName .META_TABLE_NAME )). isPresent ( )) {
208
+ if (TableName .META_TABLE_NAME . equals ( tableName )) {
209
209
future .completeExceptionally (new IOException (
210
210
"This method can't be used to locate meta regions;" + " use MetaTableLocator instead" ));
211
211
}
212
212
213
213
// Make a version of CollectingVisitor that collects RegionInfo and ServerAddress
214
- CollectingVisitor <Pair <RegionInfo , ServerName >> visitor = new CollectingVisitor <Pair <RegionInfo , ServerName >>() {
215
- private Optional <RegionLocations > current = null ;
214
+ CollectingVisitor <Pair <RegionInfo , ServerName >> visitor =
215
+ new CollectingVisitor <Pair <RegionInfo , ServerName >>() {
216
+ private RegionLocations current = null ;
216
217
217
218
@ Override
218
219
public boolean visit (Result r ) throws IOException {
219
- current = getRegionLocations (r );
220
- if (!current .isPresent () || current .get ().getRegionLocation ().getRegion () == null ) {
220
+ Optional <RegionLocations > currentRegionLocations = getRegionLocations (r );
221
+ current = currentRegionLocations .orElse (null );
222
+ if (current == null || current .getRegionLocation ().getRegion () == null ) {
221
223
LOG .warn ("No serialized RegionInfo in " + r );
222
224
return true ;
223
225
}
224
- RegionInfo hri = current .get (). getRegionLocation ().getRegion ();
226
+ RegionInfo hri = current .getRegionLocation ().getRegion ();
225
227
if (excludeOfflinedSplitParents && hri .isSplitParent ()) return true ;
226
228
// Else call super and add this Result to the collection.
227
229
return super .visit (r );
228
230
}
229
231
230
232
@ Override
231
233
void add (Result r ) {
232
- if (! current . isPresent () ) {
234
+ if (current == null ) {
233
235
return ;
234
236
}
235
- for (HRegionLocation loc : current .get (). getRegionLocations ()) {
237
+ for (HRegionLocation loc : current .getRegionLocations ()) {
236
238
if (loc != null ) {
237
239
this .results .add (new Pair <RegionInfo , ServerName >(loc .getRegion (), loc
238
240
.getServerName ()));
@@ -259,7 +261,7 @@ void add(Result r) {
259
261
* @param visitor Visitor invoked against each row
260
262
*/
261
263
private static CompletableFuture <Void > scanMeta (AsyncTable <AdvancedScanResultConsumer > metaTable ,
262
- Optional < TableName > tableName , QueryType type , final Visitor visitor ) {
264
+ TableName tableName , QueryType type , final Visitor visitor ) {
263
265
return scanMeta (metaTable , getTableStartRowForMeta (tableName , type ),
264
266
getTableStopRowForMeta (tableName , type ), type , Integer .MAX_VALUE , visitor );
265
267
}
@@ -274,15 +276,18 @@ private static CompletableFuture<Void> scanMeta(AsyncTable<AdvancedScanResultCon
274
276
* @param visitor Visitor invoked against each row
275
277
*/
276
278
private static CompletableFuture <Void > scanMeta (AsyncTable <AdvancedScanResultConsumer > metaTable ,
277
- Optional <byte []> startRow , Optional <byte []> stopRow , QueryType type , int maxRows ,
278
- final Visitor visitor ) {
279
+ byte [] startRow , byte [] stopRow , QueryType type , int maxRows , final Visitor visitor ) {
279
280
int rowUpperLimit = maxRows > 0 ? maxRows : Integer .MAX_VALUE ;
280
281
Scan scan = getMetaScan (metaTable , rowUpperLimit );
281
282
for (byte [] family : type .getFamilies ()) {
282
283
scan .addFamily (family );
283
284
}
284
- startRow .ifPresent (scan ::withStartRow );
285
- stopRow .ifPresent (scan ::withStopRow );
285
+ if (startRow != null ) {
286
+ scan .withStartRow (startRow );
287
+ }
288
+ if (stopRow != null ) {
289
+ scan .withStopRow (stopRow );
290
+ }
286
291
287
292
if (LOG .isDebugEnabled ()) {
288
293
LOG .debug ("Scanning META" + " starting at row=" + Bytes .toStringBinary (scan .getStartRow ())
@@ -466,52 +471,56 @@ private static long getSeqNumDuringOpen(final Result r, final int replicaId) {
466
471
* @param tableName table we're working with
467
472
* @return start row for scanning META according to query type
468
473
*/
469
- private static Optional <byte []> getTableStartRowForMeta (Optional <TableName > tableName ,
470
- QueryType type ) {
471
- return tableName .map ((table ) -> {
472
- switch (type ) {
473
- case REGION :
474
- case REPLICATION :
475
- byte [] startRow = new byte [table .getName ().length + 2 ];
476
- System .arraycopy (table .getName (), 0 , startRow , 0 , table .getName ().length );
477
- startRow [startRow .length - 2 ] = HConstants .DELIMITER ;
478
- startRow [startRow .length - 1 ] = HConstants .DELIMITER ;
479
- return startRow ;
480
- case ALL :
481
- case TABLE :
482
- default :
483
- return table .getName ();
474
+ private static byte [] getTableStartRowForMeta (TableName tableName , QueryType type ) {
475
+ if (tableName == null ) {
476
+ return null ;
477
+ }
478
+ switch (type ) {
479
+ case REGION :
480
+ case REPLICATION : {
481
+ byte [] startRow = new byte [tableName .getName ().length + 2 ];
482
+ System .arraycopy (tableName .getName (), 0 , startRow , 0 , tableName .getName ().length );
483
+ startRow [startRow .length - 2 ] = HConstants .DELIMITER ;
484
+ startRow [startRow .length - 1 ] = HConstants .DELIMITER ;
485
+ return startRow ;
484
486
}
485
- });
487
+ case ALL :
488
+ case TABLE :
489
+ default : {
490
+ return tableName .getName ();
491
+ }
492
+ }
486
493
}
487
494
488
495
/**
489
496
* @param tableName table we're working with
490
497
* @return stop row for scanning META according to query type
491
498
*/
492
- private static Optional <byte []> getTableStopRowForMeta (Optional <TableName > tableName ,
493
- QueryType type ) {
494
- return tableName .map ((table ) -> {
495
- final byte [] stopRow ;
496
- switch (type ) {
497
- case REGION :
498
- case REPLICATION :
499
- stopRow = new byte [table .getName ().length + 3 ];
500
- System .arraycopy (table .getName (), 0 , stopRow , 0 , table .getName ().length );
501
- stopRow [stopRow .length - 3 ] = ' ' ;
502
- stopRow [stopRow .length - 2 ] = HConstants .DELIMITER ;
503
- stopRow [stopRow .length - 1 ] = HConstants .DELIMITER ;
504
- break ;
505
- case ALL :
506
- case TABLE :
507
- default :
508
- stopRow = new byte [table .getName ().length + 1 ];
509
- System .arraycopy (table .getName (), 0 , stopRow , 0 , table .getName ().length );
510
- stopRow [stopRow .length - 1 ] = ' ' ;
511
- break ;
499
+ private static byte [] getTableStopRowForMeta (TableName tableName , QueryType type ) {
500
+ if (tableName == null ) {
501
+ return null ;
502
+ }
503
+ final byte [] stopRow ;
504
+ switch (type ) {
505
+ case REGION :
506
+ case REPLICATION : {
507
+ stopRow = new byte [tableName .getName ().length + 3 ];
508
+ System .arraycopy (tableName .getName (), 0 , stopRow , 0 , tableName .getName ().length );
509
+ stopRow [stopRow .length - 3 ] = ' ' ;
510
+ stopRow [stopRow .length - 2 ] = HConstants .DELIMITER ;
511
+ stopRow [stopRow .length - 1 ] = HConstants .DELIMITER ;
512
+ break ;
512
513
}
513
- return stopRow ;
514
- });
514
+ case ALL :
515
+ case TABLE :
516
+ default : {
517
+ stopRow = new byte [tableName .getName ().length + 1 ];
518
+ System .arraycopy (tableName .getName (), 0 , stopRow , 0 , tableName .getName ().length );
519
+ stopRow [stopRow .length - 1 ] = ' ' ;
520
+ break ;
521
+ }
522
+ }
523
+ return stopRow ;
515
524
}
516
525
517
526
/**
0 commit comments