z3n3r commented on a change in pull request #2445: URL: https://github.com/apache/hbase/pull/2445#discussion_r506774118
########## File path: hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java ########## @@ -2391,42 +2406,91 @@ public void run(Timeout timeout) throws Exception { return failedFuture(new IllegalArgumentException("Passed region name can't be null")); } try { + TableName parentTable; CompletableFuture<Optional<HRegionLocation>> future; if (RegionInfo.isEncodedRegionName(regionNameOrEncodedRegionName)) { String encodedName = Bytes.toString(regionNameOrEncodedRegionName); - if (encodedName.length() < RegionInfo.MD5_HEX_LENGTH) { - // old format encodedName, should be meta region + + //TODO francis do we really need to support encoded name for root? + boolean isRoot = false; + for (int i = 0; i< numRootReplicas; i++) { + RegionInfo info = + RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.ROOT_REGIONINFO, i); + if (Bytes.equals(info.getRegionName(), regionNameOrEncodedRegionName)) { + isRoot = true; + break; + } + } + if (isRoot) { future = connection.registry.getMetaRegionLocations() .thenApply(locs -> Stream.of(locs.getRegionLocations()) .filter(loc -> loc.getRegion().getEncodedName().equals(encodedName)).findFirst()); + parentTable = null; + } else if (encodedName.length() < RegionInfo.MD5_HEX_LENGTH) { + future = ClientMetaTableAccessor.getRegionLocationWithEncodedName(rootTable, + regionNameOrEncodedRegionName); + parentTable = ROOT_TABLE_NAME; } else { future = ClientMetaTableAccessor.getRegionLocationWithEncodedName(metaTable, regionNameOrEncodedRegionName); + parentTable = META_TABLE_NAME; } } else { RegionInfo regionInfo = CatalogFamilyFormat.parseRegionInfoFromRegionName(regionNameOrEncodedRegionName); - if (regionInfo.isMetaRegion()) { + if (regionInfo.isRootRegion()) { future = connection.registry.getMetaRegionLocations() .thenApply(locs -> Stream.of(locs.getRegionLocations()) .filter(loc -> loc.getRegion().getReplicaId() == regionInfo.getReplicaId()) .findFirst()); + parentTable = null; + //TODO francis it won't reach here once meta is split + } else if (regionInfo.isMetaRegion()) { + parentTable = ROOT_TABLE_NAME; + future = + ClientMetaTableAccessor.getRegionLocation(rootTable, regionNameOrEncodedRegionName); } else { + parentTable = META_TABLE_NAME; future = ClientMetaTableAccessor.getRegionLocation(metaTable, regionNameOrEncodedRegionName); } } + final TableName finalParentTable = parentTable; CompletableFuture<HRegionLocation> returnedFuture = new CompletableFuture<>(); addListener(future, (location, err) -> { if (err != null) { returnedFuture.completeExceptionally(err); return; } if (!location.isPresent() || location.get().getRegion() == null) { - returnedFuture.completeExceptionally( - new UnknownRegionException("Invalid region name or encoded region name: " + - Bytes.toStringBinary(regionNameOrEncodedRegionName))); + if (META_TABLE_NAME.equals(finalParentTable)) { + if (LOG.isDebugEnabled()) { Review comment: I was trying to avoid the Bytes.toString() binary execution. That's inconsequential? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org