-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HBASE-29082: Support for custom meta table name suffix #6632
base: HBASE-29081
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,10 @@ | |
*/ | ||
package org.apache.hadoop.hbase; | ||
|
||
import com.google.errorprone.annotations.RestrictedApi; | ||
import java.nio.ByteBuffer; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import org.apache.hadoop.conf.Configuration; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import java.util.Set; | ||
|
@@ -27,6 +30,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 | ||
|
@@ -44,6 +49,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<>(); | ||
|
@@ -65,9 +72,34 @@ 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); | ||
} | ||
|
||
/* Visible for testing only */ | ||
@RestrictedApi(explanation = "Should only be called in tests", link = "", | ||
allowedOnPath = ".*/src/test/.*") | ||
public static TableName getDefaultNameOfMetaForReplica() { | ||
return valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "meta"); | ||
} | ||
|
||
public 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.info("Meta table name: {}", META_TABLE_NAME); | ||
return TableName.META_TABLE_NAME; | ||
} | ||
Comment on lines
+94
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incorrect: META_TABLE_NAME is being initialized in this method, so you end up returning null value. |
||
TableName META_TABLE = valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, | ||
"meta_" + suffix_val);; | ||
LOG.info("Meta table name: {}", META_TABLE); | ||
return META_TABLE; | ||
} | ||
|
||
/** | ||
* The Namespace table's name. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -28,6 +29,8 @@ | |
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
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; | ||
|
@@ -61,9 +64,14 @@ public class InitMetaProcedure extends AbstractStateMachineTableProcedure<InitMe | |
|
||
private RetryCounter retryCounter; | ||
|
||
protected final Configuration conf; | ||
public InitMetaProcedure(Configuration conf) { | ||
this.conf = conf; | ||
} | ||
|
||
Comment on lines
+67
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably don't need this constructor at all if you return |
||
@Override | ||
public TableName getTableName() { | ||
return TableName.META_TABLE_NAME; | ||
return TableName.initializeHbaseMetaTableName(conf); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
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.hbase.client.Connection; | ||
import org.apache.hadoop.hbase.client.ConnectionFactory; | ||
import org.apache.hadoop.hbase.client.RegionInfo; | ||
import org.apache.hadoop.hbase.master.HMaster; | ||
import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
import org.apache.hadoop.hbase.testclassification.MiscTests; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.apache.hadoop.hbase.util.Pair; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.rules.TestName; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Test {@link org.apache.hadoop.hbase.TestMetaTableForReplica}. | ||
*/ | ||
@Category({ MiscTests.class, MediumTests.class }) | ||
@SuppressWarnings("deprecation") | ||
public class TestMetaTableForReplica { | ||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestMetaTableForReplica.class); | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(TestMetaTableForReplica.class); | ||
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); | ||
private static Connection connection; | ||
|
||
@Rule | ||
public TestName name = new TestName(); | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
Configuration c = new Configuration(UTIL.getConfiguration()); | ||
//Start cluster having non-default hbase meta table name | ||
c.setStrings(HConstants.HBASE_META_TABLE_SUFFIX,"test"); | ||
UTIL.startMiniCluster(3); | ||
connection = ConnectionFactory.createConnection(c); | ||
} | ||
|
||
@AfterClass | ||
public static void afterClass() throws Exception { | ||
connection.close(); | ||
UTIL.shutdownMiniCluster(); | ||
} | ||
|
||
@Test | ||
public void testStateOfMetaForReplica() { | ||
HMaster m = UTIL.getMiniHBaseCluster().getMaster(); | ||
assertTrue(m.waitForMetaOnline()); | ||
} | ||
|
||
@Test | ||
public void testNameOfMetaForReplica() { | ||
//Check the correctness of the meta table for replica | ||
String metaTableName = TableName.META_TABLE_NAME.getNameWithNamespaceInclAsString(); | ||
assertNotNull(metaTableName); | ||
|
||
//Check if name of the meta table for replica is not same as default table | ||
assertEquals(0, TableName.META_TABLE_NAME.compareTo( | ||
TableName.getDefaultNameOfMetaForReplica())); | ||
} | ||
|
||
@Test | ||
public void testGetNonExistentRegionFromMetaFromReplica() throws IOException { | ||
final String name = this.name.getMethodName(); | ||
LOG.info("Started " + name); | ||
Pair<RegionInfo, ServerName> pair = | ||
MetaTableAccessor.getRegion(connection, Bytes.toBytes("nonexistent-region")); | ||
assertNull(pair); | ||
LOG.info("Finished " + name); | ||
} | ||
|
||
@Test | ||
public void testGetExistentRegionFromMetaFromReplica() throws IOException { | ||
final TableName tableName = TableName.valueOf(name.getMethodName()); | ||
LOG.info("Started " + tableName); | ||
UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); | ||
assertEquals(1, MetaTableAccessor.getTableRegions(connection, tableName).size()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meta table suffix is just a string. I think this should be
conf.get(...)