@@ -2394,51 +2394,55 @@ CompletableFuture<HRegionLocation> getRegionLocation(byte[] regionNameOrEncodedR
23942394 if (regionNameOrEncodedRegionName == null ) {
23952395 return failedFuture (new IllegalArgumentException ("Passed region name can't be null" ));
23962396 }
2397- try {
2398- CompletableFuture <Optional <HRegionLocation >> future ;
2399- if (RegionInfo .isEncodedRegionName (regionNameOrEncodedRegionName )) {
2400- String encodedName = Bytes .toString (regionNameOrEncodedRegionName );
2401- if (encodedName .length () < RegionInfo .MD5_HEX_LENGTH ) {
2402- // old format encodedName, should be meta region
2403- future = connection .registry .getMetaRegionLocations ()
2404- .thenApply (locs -> Stream .of (locs .getRegionLocations ())
2405- .filter (loc -> loc .getRegion ().getEncodedName ().equals (encodedName )).findFirst ());
2406- } else {
2407- future = AsyncMetaTableAccessor .getRegionLocationWithEncodedName (metaTable ,
2408- regionNameOrEncodedRegionName );
2409- }
2397+
2398+ CompletableFuture <Optional <HRegionLocation >> future ;
2399+ if (RegionInfo .isEncodedRegionName (regionNameOrEncodedRegionName )) {
2400+ String encodedName = Bytes .toString (regionNameOrEncodedRegionName );
2401+ if (encodedName .length () < RegionInfo .MD5_HEX_LENGTH ) {
2402+ // old format encodedName, should be meta region
2403+ future = connection .registry .getMetaRegionLocations ()
2404+ .thenApply (locs -> Stream .of (locs .getRegionLocations ())
2405+ .filter (loc -> loc .getRegion ().getEncodedName ().equals (encodedName )).findFirst ());
24102406 } else {
2411- RegionInfo regionInfo =
2412- MetaTableAccessor . parseRegionInfoFromRegionName ( regionNameOrEncodedRegionName );
2413- if ( regionInfo . isMetaRegion ()) {
2414- future = connection . registry . getMetaRegionLocations ()
2415- . thenApply ( locs -> Stream . of ( locs . getRegionLocations ())
2416- . filter ( loc -> loc . getRegion (). getReplicaId () == regionInfo . getReplicaId ())
2417- . findFirst ()) ;
2418- } else {
2419- future =
2420- AsyncMetaTableAccessor . getRegionLocation ( metaTable , regionNameOrEncodedRegionName );
2421- }
2407+ future = AsyncMetaTableAccessor . getRegionLocationWithEncodedName ( metaTable ,
2408+ regionNameOrEncodedRegionName );
2409+ }
2410+ } else {
2411+ // Not all regionNameOrEncodedRegionName here is going to be a valid region name,
2412+ // it needs to throw out IllegalArgumentException in case tableName is passed in.
2413+ RegionInfo regionInfo ;
2414+ try {
2415+ regionInfo = MetaTableAccessor . parseRegionInfoFromRegionName ( regionNameOrEncodedRegionName );
2416+ } catch ( IOException ioe ) {
2417+ return failedFuture ( new IllegalArgumentException ( ioe . getMessage ()));
24222418 }
24232419
2424- CompletableFuture <HRegionLocation > returnedFuture = new CompletableFuture <>();
2425- addListener (future , (location , err ) -> {
2426- if (err != null ) {
2427- returnedFuture .completeExceptionally (err );
2428- return ;
2429- }
2430- if (!location .isPresent () || location .get ().getRegion () == null ) {
2431- returnedFuture .completeExceptionally (
2432- new UnknownRegionException ("Invalid region name or encoded region name: " +
2433- Bytes .toStringBinary (regionNameOrEncodedRegionName )));
2434- } else {
2435- returnedFuture .complete (location .get ());
2436- }
2437- });
2438- return returnedFuture ;
2439- } catch (IOException e ) {
2440- return failedFuture (e );
2420+ if (regionInfo .isMetaRegion ()) {
2421+ future = connection .registry .getMetaRegionLocations ()
2422+ .thenApply (locs -> Stream .of (locs .getRegionLocations ())
2423+ .filter (loc -> loc .getRegion ().getReplicaId () == regionInfo .getReplicaId ())
2424+ .findFirst ());
2425+ } else {
2426+ future =
2427+ AsyncMetaTableAccessor .getRegionLocation (metaTable , regionNameOrEncodedRegionName );
2428+ }
24412429 }
2430+
2431+ CompletableFuture <HRegionLocation > returnedFuture = new CompletableFuture <>();
2432+ addListener (future , (location , err ) -> {
2433+ if (err != null ) {
2434+ returnedFuture .completeExceptionally (err );
2435+ return ;
2436+ }
2437+ if (!location .isPresent () || location .get ().getRegion () == null ) {
2438+ returnedFuture .completeExceptionally (
2439+ new UnknownRegionException ("Invalid region name or encoded region name: " +
2440+ Bytes .toStringBinary (regionNameOrEncodedRegionName )));
2441+ } else {
2442+ returnedFuture .complete (location .get ());
2443+ }
2444+ });
2445+ return returnedFuture ;
24422446 }
24432447
24442448 /**
0 commit comments