@@ -424,74 +424,76 @@ public static List<InputSplit> getSplits(Scan scan, SnapshotManifest manifest,
424424
425425 Connection connection = null ;
426426 RegionLocator regionLocator = null ;
427- if (localityEnabled && useRegionLoc ) {
428- Configuration newConf = new Configuration (conf );
429- newConf .setInt ("hbase.hconnection.threads.max" , 1 );
430- try {
427+ List <InputSplit > splits = new ArrayList <>();
428+ try {
429+ if (localityEnabled && useRegionLoc ) {
430+ Configuration newConf = new Configuration (conf );
431+ newConf .setInt ("hbase.hconnection.threads.max" , 1 );
432+
431433 connection = ConnectionFactory .createConnection (newConf );
432434 regionLocator = connection .getRegionLocator (htd .getTableName ());
433435
434436 /* Get all locations for the table and cache it */
435437 regionLocator .getAllRegionLocations ();
436- } finally {
437- if (connection != null ) {
438- connection .close ();
439- }
440438 }
441- }
442439
443- List < InputSplit > splits = new ArrayList <>();
444- for ( RegionInfo hri : regionManifests ) {
445- // load region descriptor
446- List < String > hosts = null ;
447- if (localityEnabled ) {
448- if ( regionLocator != null ) {
449- /* Get Location from the local cache */
450- HRegionLocation location = regionLocator . getRegionLocation ( hri . getStartKey (), false );
451-
452- hosts = new ArrayList <>( 1 );
453- hosts . add ( location . getHostname ());
454- } else {
455- hosts = calculateLocationsForInputSplit ( conf , htd , hri , tableDir );
440+ for ( RegionInfo hri : regionManifests ) {
441+ // load region descriptor
442+ List < String > hosts = null ;
443+ if ( localityEnabled ) {
444+ if (regionLocator != null ) {
445+ /* Get Location from the local cache */
446+ HRegionLocation location = regionLocator . getRegionLocation ( hri . getStartKey (), false );
447+
448+ hosts = new ArrayList <>( 1 );
449+ hosts . add ( location . getHostname () );
450+ } else {
451+ hosts = calculateLocationsForInputSplit ( conf , htd , hri , tableDir );
452+ }
456453 }
457- }
458454
459- if (numSplits > 1 ) {
460- byte [][] sp = sa .split (hri .getStartKey (), hri .getEndKey (), numSplits , true );
461- for (int i = 0 ; i < sp .length - 1 ; i ++) {
455+ if (numSplits > 1 ) {
456+ byte [][] sp = sa .split (hri .getStartKey (), hri .getEndKey (), numSplits , true );
457+ for (int i = 0 ; i < sp .length - 1 ; i ++) {
458+ if (
459+ PrivateCellUtil .overlappingKeys (scan .getStartRow (), scan .getStopRow (), sp [i ],
460+ sp [i + 1 ])
461+ ) {
462+
463+ Scan boundedScan = new Scan (scan );
464+ if (scan .getStartRow ().length == 0 ) {
465+ boundedScan .withStartRow (sp [i ]);
466+ } else {
467+ boundedScan .withStartRow (
468+ Bytes .compareTo (scan .getStartRow (), sp [i ]) > 0 ? scan .getStartRow () : sp [i ]);
469+ }
470+
471+ if (scan .getStopRow ().length == 0 ) {
472+ boundedScan .withStopRow (sp [i + 1 ]);
473+ } else {
474+ boundedScan .withStopRow (Bytes .compareTo (scan .getStopRow (), sp [i + 1 ]) < 0
475+ ? scan .getStopRow ()
476+ : sp [i + 1 ]);
477+ }
478+
479+ splits .add (new InputSplit (htd , hri , hosts , boundedScan , restoreDir ));
480+ }
481+ }
482+ } else {
462483 if (
463- PrivateCellUtil .overlappingKeys (scan .getStartRow (), scan .getStopRow (), sp [i ], sp [i + 1 ])
484+ PrivateCellUtil .overlappingKeys (scan .getStartRow (), scan .getStopRow (),
485+ hri .getStartKey (), hri .getEndKey ())
464486 ) {
465487
466- Scan boundedScan = new Scan (scan );
467- if (scan .getStartRow ().length == 0 ) {
468- boundedScan .withStartRow (sp [i ]);
469- } else {
470- boundedScan .withStartRow (
471- Bytes .compareTo (scan .getStartRow (), sp [i ]) > 0 ? scan .getStartRow () : sp [i ]);
472- }
473-
474- if (scan .getStopRow ().length == 0 ) {
475- boundedScan .withStopRow (sp [i + 1 ]);
476- } else {
477- boundedScan .withStopRow (
478- Bytes .compareTo (scan .getStopRow (), sp [i + 1 ]) < 0 ? scan .getStopRow () : sp [i + 1 ]);
479- }
480-
481- splits .add (new InputSplit (htd , hri , hosts , boundedScan , restoreDir ));
488+ splits .add (new InputSplit (htd , hri , hosts , scan , restoreDir ));
482489 }
483490 }
484- } else {
485- if (
486- PrivateCellUtil .overlappingKeys (scan .getStartRow (), scan .getStopRow (), hri .getStartKey (),
487- hri .getEndKey ())
488- ) {
489-
490- splits .add (new InputSplit (htd , hri , hosts , scan , restoreDir ));
491- }
491+ }
492+ } finally {
493+ if (connection != null ) {
494+ connection .close ();
492495 }
493496 }
494-
495497 return splits ;
496498 }
497499
0 commit comments