This is an automated email from the ASF dual-hosted git repository.
andor pushed a commit to branch HBASE-29081_rebased
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/HBASE-29081_rebased by this
push:
new 0c897a67e45 HBASE-29992: Implement regex check for configured replica
suffix (#7923)
0c897a67e45 is described below
commit 0c897a67e4598f3dc89777c3845b0d4099d6fc56
Author: Kota-SH <[email protected]>
AuthorDate: Mon Mar 23 13:34:20 2026 -0500
HBASE-29992: Implement regex check for configured replica suffix (#7923)
---
.../java/org/apache/hadoop/hbase/TableName.java | 6 ++++++
.../org/apache/hadoop/hbase/TestTableName.java | 24 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
index 73008c7ad5f..263ed91103e 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
@@ -70,6 +70,7 @@ public final class TableName implements Comparable<TableName>
{
// with NAMESPACE_DELIM as delimiter
public static final String VALID_USER_TABLE_REGEX = "(?:(?:(?:" +
VALID_NAMESPACE_REGEX + "\\"
+ NAMESPACE_DELIM + ")?)" + "(?:" + VALID_TABLE_QUALIFIER_REGEX + "))";
+ public static final String VALID_META_TABLE_SUFFIX_REGEX = "[a-zA-Z0-9]+";
/**
* The name of hbase meta table could either be hbase:meta_xxx or
'hbase:meta' otherwise. Config
@@ -96,6 +97,11 @@ public final class TableName implements
Comparable<TableName> {
if (Strings.isNullOrEmpty(suffix_val)) {
return valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "meta");
} else {
+ if (!suffix_val.matches(VALID_META_TABLE_SUFFIX_REGEX)) {
+ throw new IllegalArgumentException("Invalid value '" + suffix_val + "'
for config '"
+ + HConstants.HBASE_META_TABLE_SUFFIX + "'. Suffix must only contain
ASCII letters and "
+ + "digits matching: " + VALID_META_TABLE_SUFFIX_REGEX);
+ }
return valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "meta_" +
suffix_val);
}
}
diff --git
a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
index d9281d8953e..f145842a23d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertThrows;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
+import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
@@ -164,4 +165,27 @@ public class TestTableName {
assertArrayEquals(expected.getNamespace(), names.nsb);
return expected;
}
+
+ @Test
+ public void testValidMetaTableSuffix() {
+ String[] validSuffixes = { "REPL1", "123", "123abc" };
+ for (String suffix : validSuffixes) {
+ Configuration conf = HBaseConfiguration.create();
+ conf.set(HConstants.HBASE_META_TABLE_SUFFIX, suffix);
+ TableName metaTableName = TableName.initializeHbaseMetaTableName(conf);
+ assertEquals("hbase:meta_" + suffix, metaTableName.getNameAsString());
+ }
+ }
+
+ @Test
+ public void testInvalidMetaTableSuffix() {
+ String[] invalidSuffixes = { "test_1", "test-1", "test.1", "test 1",
"_test", "-test", ".test",
+ "has!special", "has:colon", " " };
+ for (String suffix : invalidSuffixes) {
+ Configuration conf = HBaseConfiguration.create();
+ conf.set(HConstants.HBASE_META_TABLE_SUFFIX, suffix);
+ assertThrows("Expected IllegalArgumentException for suffix: " + suffix,
+ IllegalArgumentException.class, () ->
TableName.initializeHbaseMetaTableName(conf));
+ }
+ }
}