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
commit a649a39d973841fe04a3fcb34ede45bae1efcf68 Author: Kota-SH <[email protected]> AuthorDate: Mon Oct 20 10:37:49 2025 -0400 HBASE-29594: Add suffix to Master Region data directory (#7330) --- .../hbase/master/region/MasterRegionFactory.java | 28 ++++++++++++++++++++-- .../store/region/HFileProcedurePrettyPrinter.java | 2 +- .../master/region/TestMasterRegionInitialize.java | 18 ++++++++++++++ .../region/TestHFileProcedurePrettyPrinter.java | 2 +- .../region/TestWALProcedurePrettyPrinter.java | 2 +- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/region/MasterRegionFactory.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/region/MasterRegionFactory.java index 878f8dc17a1..cec8cd4ce9e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/region/MasterRegionFactory.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/region/MasterRegionFactory.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.master.region; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -34,6 +35,8 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ReflectionUtils; import org.apache.yetus.audience.InterfaceAudience; +import org.apache.hbase.thirdparty.com.google.common.base.Strings; + /** * The factory class for creating a {@link MasterRegion}. */ @@ -54,7 +57,24 @@ public final class MasterRegionFactory { public static final String USE_HSYNC_KEY = "hbase.master.store.region.wal.hsync"; - public static final String MASTER_STORE_DIR = "MasterData"; + // Default master data dir + private static final String MASTER_REGION_DIR_NAME_DEFAULT = "MasterData"; + + private static final String MASTER_REGION_DIR_NAME; + static { + Configuration conf = HBaseConfiguration.create(); + MASTER_REGION_DIR_NAME = initMasterRegionDirName(conf); + } + + public static String initMasterRegionDirName(Configuration conf) { + String suffix = conf.get(HConstants.HBASE_META_TABLE_SUFFIX, + HConstants.HBASE_META_TABLE_SUFFIX_DEFAULT_VALUE); + if (Strings.isNullOrEmpty(suffix)) { + return MASTER_REGION_DIR_NAME_DEFAULT; + } else { + return MASTER_REGION_DIR_NAME_DEFAULT + "_" + suffix; + } + } private static final String FLUSH_SIZE_KEY = "hbase.master.store.region.flush.size"; @@ -116,7 +136,7 @@ public final class MasterRegionFactory { public static MasterRegion create(MasterServices server) throws IOException { Configuration conf = server.getConfiguration(); MasterRegionParams params = new MasterRegionParams().server(server) - .regionDirName(MASTER_STORE_DIR).tableDescriptor(withTrackerConfigs(conf)); + .regionDirName(getMasterRegionDirName()).tableDescriptor(withTrackerConfigs(conf)); long flushSize = conf.getLong(FLUSH_SIZE_KEY, DEFAULT_FLUSH_SIZE); long flushPerChanges = conf.getLong(FLUSH_PER_CHANGES_KEY, DEFAULT_FLUSH_PER_CHANGES); long flushIntervalMs = conf.getLong(FLUSH_INTERVAL_MS_KEY, DEFAULT_FLUSH_INTERVAL_MS); @@ -134,4 +154,8 @@ public final class MasterRegionFactory { .archivedHFileSuffix(ARCHIVED_HFILE_SUFFIX); return MasterRegion.create(params); } + + public static String getMasterRegionDirName() { + return MASTER_REGION_DIR_NAME; + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java index c254201db9b..0752c814f38 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure2/store/region/HFileProcedurePrettyPrinter.java @@ -85,7 +85,7 @@ public class HFileProcedurePrettyPrinter extends AbstractHBaseTool { private void addAllHFiles() throws IOException { Path masterProcDir = - new Path(CommonFSUtils.getRootDir(conf), MasterRegionFactory.MASTER_STORE_DIR); + new Path(CommonFSUtils.getRootDir(conf), MasterRegionFactory.getMasterRegionDirName()); Path tableDir = CommonFSUtils.getTableDir(masterProcDir, MasterRegionFactory.TABLE_NAME); FileSystem fs = tableDir.getFileSystem(conf); Path regionDir = diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionInitialize.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionInitialize.java index 8b6f4670732..20bd4ada48d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionInitialize.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionInitialize.java @@ -24,8 +24,11 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.TableDescriptor; @@ -114,4 +117,19 @@ public class TestMasterRegionInitialize extends MasterRegionTestBase { // but the data should have been cleaned up assertTrue(region.get(new Get(row)).isEmpty()); } + + @Test + public void testMasterRegionDirSuffix() { + String currentMasterRegionDirName = MasterRegionFactory.getMasterRegionDirName(); + assertEquals("Default master region directory should be MasterData", "MasterData", + currentMasterRegionDirName); + + Configuration confWithSuffix = HBaseConfiguration.create(); + String suffix = "replica1"; + confWithSuffix.set(HConstants.HBASE_META_TABLE_SUFFIX, suffix); + String dirNameWithSuffix = MasterRegionFactory.initMasterRegionDirName(confWithSuffix); + String expectedDirName = "MasterData_" + suffix; + assertEquals("Directory name should have suffix when configured", expectedDirName, + dirNameWithSuffix); + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure2/store/region/TestHFileProcedurePrettyPrinter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure2/store/region/TestHFileProcedurePrettyPrinter.java index b85897a1afa..0a99f27eb60 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure2/store/region/TestHFileProcedurePrettyPrinter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure2/store/region/TestHFileProcedurePrettyPrinter.java @@ -102,7 +102,7 @@ public class TestHFileProcedurePrettyPrinter extends RegionProcedureStoreTestBas store.cleanup(); store.region.flush(true); Path tableDir = CommonFSUtils.getTableDir( - new Path(htu.getDataTestDir(), MasterRegionFactory.MASTER_STORE_DIR), + new Path(htu.getDataTestDir(), MasterRegionFactory.getMasterRegionDirName()), MasterRegionFactory.TABLE_NAME); FileSystem fs = tableDir.getFileSystem(htu.getConfiguration()); Path regionDir = diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure2/store/region/TestWALProcedurePrettyPrinter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure2/store/region/TestWALProcedurePrettyPrinter.java index d942c65b8c7..2875c9f467b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure2/store/region/TestWALProcedurePrettyPrinter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/procedure2/store/region/TestWALProcedurePrettyPrinter.java @@ -64,7 +64,7 @@ public class TestWALProcedurePrettyPrinter extends RegionProcedureStoreTestBase } store.cleanup(); Path walParentDir = new Path(htu.getDataTestDir(), - MasterRegionFactory.MASTER_STORE_DIR + "/" + HConstants.HREGION_LOGDIR_NAME); + MasterRegionFactory.getMasterRegionDirName() + "/" + HConstants.HREGION_LOGDIR_NAME); FileSystem fs = walParentDir.getFileSystem(htu.getConfiguration()); Path walDir = fs.listStatus(walParentDir)[0].getPath(); Path walFile = fs.listStatus(walDir)[0].getPath();
