HBASE-25368 Filter out more invalid encoded name in isEncodedRegionName(byte[] regionName) (#2753)
Signed-off-by: stack <stack@apache.com>
This commit is contained in:
parent
1c217da2ff
commit
c327680125
|
@ -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,8 +2402,16 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
|||
regionNameOrEncodedRegionName);
|
||||
}
|
||||
} else {
|
||||
RegionInfo regionInfo =
|
||||
CatalogFamilyFormat.parseRegionInfoFromRegionName(regionNameOrEncodedRegionName);
|
||||
// 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());
|
||||
}
|
||||
|
||||
if (regionInfo.isMetaRegion()) {
|
||||
future = connection.registry.getMetaRegionLocations()
|
||||
.thenApply(locs -> Stream.of(locs.getRegionLocations())
|
||||
|
@ -2430,9 +2438,6 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
|||
}
|
||||
});
|
||||
return returnedFuture;
|
||||
} catch (IOException e) {
|
||||
return failedFuture(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -363,7 +363,23 @@ 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.
|
||||
return parseRegionNameOrReturnNull(regionName) == null && regionName.length <= MD5_HEX_LENGTH;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,6 +99,25 @@ 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());
|
||||
|
|
Loading…
Reference in New Issue