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