Revert "HBASE-25368 Filter out more invalid encoded name in isEncodedRegionName(byte[] regionName) (#2753)"

This reverts commit c327680125.
This commit is contained in:
Duo Zhang 2020-12-19 20:28:30 +08:00
parent f600856a3b
commit 33441f540a
3 changed files with 42 additions and 82 deletions

View File

@ -2388,7 +2388,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
if (regionNameOrEncodedRegionName == null) {
return failedFuture(new IllegalArgumentException("Passed region name can't be null"));
}
try {
CompletableFuture<Optional<HRegionLocation>> future;
if (RegionInfo.isEncodedRegionName(regionNameOrEncodedRegionName)) {
String encodedName = Bytes.toString(regionNameOrEncodedRegionName);
@ -2402,16 +2402,8 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
regionNameOrEncodedRegionName);
}
} else {
// Not all regionNameOrEncodedRegionName here is going to be a valid region name,
// it needs to throw out IllegalArgumentException in case tableName is passed in.
RegionInfo regionInfo;
try {
regionInfo = CatalogFamilyFormat.parseRegionInfoFromRegionName(
regionNameOrEncodedRegionName);
} catch (IOException ioe) {
throw new IllegalArgumentException(ioe.getMessage());
}
RegionInfo regionInfo =
CatalogFamilyFormat.parseRegionInfoFromRegionName(regionNameOrEncodedRegionName);
if (regionInfo.isMetaRegion()) {
future = connection.registry.getMetaRegionLocations()
.thenApply(locs -> Stream.of(locs.getRegionLocations())
@ -2438,6 +2430,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
}
});
return returnedFuture;
} catch (IOException e) {
return failedFuture(e);
}
}
/**

View File

@ -363,23 +363,7 @@ public interface RegionInfo extends Comparable<RegionInfo> {
@InterfaceAudience.Private // For use by internals only.
public static boolean isEncodedRegionName(byte[] regionName) {
// If not parseable as region name, presume encoded. TODO: add stringency; e.g. if hex.
if (parseRegionNameOrReturnNull(regionName) == null) {
if (regionName.length > MD5_HEX_LENGTH) {
return false;
} else if (regionName.length == MD5_HEX_LENGTH) {
return true;
} else {
String encodedName = Bytes.toString(regionName);
try {
Integer.parseInt(encodedName);
// If this is a valid integer, it could be hbase:meta's encoded region name.
return true;
} catch(NumberFormatException er) {
return false;
}
}
}
return false;
return parseRegionNameOrReturnNull(regionName) == null && regionName.length <= MD5_HEX_LENGTH;
}
/**

View File

@ -99,25 +99,6 @@ public class TestAdmin1 extends TestAdminBase {
assertTrue(exception instanceof TableNotFoundException);
}
@Test
public void testCompactATableWithSuperLongTableName() throws Exception {
TableName tableName = TableName.valueOf(name.getMethodName());
TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam1")).build();
try {
ADMIN.createTable(htd);
try {
ADMIN.majorCompactRegion(tableName.getName());
ADMIN.majorCompactRegion(Bytes.toBytes("abcd"));
} catch (IllegalArgumentException iae) {
LOG.info("This is expected");
}
} finally {
ADMIN.disableTable(tableName);
ADMIN.deleteTable(tableName);
}
}
@Test
public void testCompactionTimestamps() throws Exception {
TableName tableName = TableName.valueOf(name.getMethodName());