Skip to content

Commit

Permalink
HBASE-29082: Support for custom meta table name suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
kabhishek4 committed Jan 24, 2025
1 parent 28f1b51 commit 7313eda
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
13 changes: 13 additions & 0 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,19 @@ public enum OperationStatusCode {
*/
public final static boolean REJECT_DECOMMISSIONED_HOSTS_DEFAULT = false;

/**
* Adds a suffix to the meta table name: value=’test’ -> ‘hbase:meta_test’
* Added in HBASE-XXXXX to support having multiple hbase:meta tables (with distinct names )to
* enable storage sharing by more than one clusters.
*/

public final static String HBASE_META_TABLE_SUFFIX = "hbase.meta.table.suffix";

/**
* Default value of {@link #HBASE_META_TABLE_SUFFIX}
*/
public final static String HBASE_META_TABLE_SUFFIX_DEFAULT_VALUE = "";

private HConstants() {
// Can't be instantiated with this ctor.
}
Expand Down
28 changes: 25 additions & 3 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hbase;

import java.nio.ByteBuffer;
import org.apache.hadoop.conf.Configuration;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Set;
Expand All @@ -27,6 +28,8 @@
import org.apache.yetus.audience.InterfaceAudience;

import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Immutable POJO class for representing a table name. Which is of the form: <table
Expand All @@ -44,6 +47,8 @@
*/
@InterfaceAudience.Public
public final class TableName implements Comparable<TableName> {
private static final Logger LOG = LoggerFactory.getLogger(TableName.class);


/** See {@link #createTableNameIfNecessary(ByteBuffer, ByteBuffer)} */
private static final Set<TableName> tableCache = new CopyOnWriteArraySet<>();
Expand All @@ -65,9 +70,26 @@ public final class TableName implements Comparable<TableName> {
public static final String VALID_USER_TABLE_REGEX = "(?:(?:(?:" + VALID_NAMESPACE_REGEX + "\\"
+ NAMESPACE_DELIM + ")?)" + "(?:" + VALID_TABLE_QUALIFIER_REGEX + "))";

/** The hbase:meta table's name. */
public static final TableName META_TABLE_NAME =
valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "meta");
/** The name of hbase meta table could either be hbase:meta_xxx or 'hbase:meta' otherwise.
* Config hbase.meta.table.suffix will govern the decision of adding suffix to the habase:meta */
public static final TableName META_TABLE_NAME;
static {
Configuration conf = HBaseConfiguration.create();
META_TABLE_NAME = initializeHbaseMetaTableName(conf);
}

static TableName initializeHbaseMetaTableName(Configuration conf) {
String suffix_val = String.valueOf(conf.getStrings(
HConstants.HBASE_META_TABLE_SUFFIX, HConstants.HBASE_META_TABLE_SUFFIX_DEFAULT_VALUE));

if (suffix_val == null||suffix_val.isEmpty()) {
LOG.debug("Default value for Hbase meta table is being chosen.");
return TableName.META_TABLE_NAME;
}
LOG.debug("Suffix value for Hbase meta table is being chosen.");
return valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "meta_"
+ suffix_val);
}

/**
* The Namespace table's name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ private void finishActiveMasterInitialization() throws IOException, InterruptedE
.filter(p -> p instanceof InitMetaProcedure).map(o -> (InitMetaProcedure) o).findAny();
initMetaProc = optProc.orElseGet(() -> {
// schedule an init meta procedure if meta has not been deployed yet
InitMetaProcedure temp = new InitMetaProcedure();
InitMetaProcedure temp = new InitMetaProcedure(conf);
procedureExecutor.submitProcedure(temp);
return temp;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.apache.hadoop.hbase.NamespaceDescriptor.DEFAULT_NAMESPACE;
import static org.apache.hadoop.hbase.NamespaceDescriptor.SYSTEM_NAMESPACE;
import static org.apache.hadoop.hbase.TableName.valueOf;
import static org.apache.hadoop.hbase.master.TableNamespaceManager.insertNamespaceToMeta;
import static org.apache.hadoop.hbase.master.procedure.AbstractStateMachineNamespaceProcedure.createDirectory;

Expand All @@ -28,6 +29,9 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseIOException;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.TableDescriptor;
Expand Down Expand Up @@ -61,9 +65,21 @@ public class InitMetaProcedure extends AbstractStateMachineTableProcedure<InitMe

private RetryCounter retryCounter;

protected final Configuration conf;
public InitMetaProcedure(Configuration conf) {
this.conf = conf;
}

@Override
public TableName getTableName() {
return TableName.META_TABLE_NAME;
String suffix_val = String.valueOf(conf.getStrings(
HConstants.HBASE_META_TABLE_SUFFIX, HConstants.HBASE_META_TABLE_SUFFIX_DEFAULT_VALUE));

if (suffix_val == null||suffix_val.isEmpty()) {
return TableName.META_TABLE_NAME;
}
return valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "meta_"
+ suffix_val);
}

@Override
Expand All @@ -78,6 +94,7 @@ private static TableDescriptor writeFsLayout(Path rootDir, Configuration conf)
Path tableDir = CommonFSUtils.getTableDir(rootDir, TableName.META_TABLE_NAME);
if (fs.exists(tableDir) && !fs.delete(tableDir, true)) {
LOG.warn("Can not delete partial created meta table, continue...");
throw new HBaseIOException("Specified meta table already exists.");
}
// Bootstrapping, make sure blockcache is off. Else, one will be
// created here in bootstrap and it'll need to be cleaned up. Better to
Expand Down

0 comments on commit 7313eda

Please sign in to comment.