You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zy...@apache.org on 2018/07/10 04:39:10 UTC

[48/50] [abbrv] hbase git commit: HBASE-18444 Add support for specifying custom meta table suffix

HBASE-18444 Add support for specifying custom meta table suffix

Signed-off-by: tedyu <yu...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/0da6e5dd
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/0da6e5dd
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/0da6e5dd

Branch: refs/heads/HBASE-18477
Commit: 0da6e5dd0a3b19909f403136916c67b113e0318b
Parents: d7561ce
Author: Ajay Jadhav <ja...@amazon.com>
Authored: Fri Sep 1 17:14:57 2017 -0700
Committer: Zach York <zy...@apache.org>
Committed: Mon Jul 9 21:21:09 2018 -0700

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hbase/TableName.java | 40 ++++++++++++-
 .../org/apache/hadoop/hbase/TestTableName.java  | 62 ++++++++++++++++----
 2 files changed, 89 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/0da6e5dd/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
----------------------------------------------------------------------
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 e6cabbc..7e68938 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
@@ -24,9 +24,15 @@ import java.util.Arrays;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.yetus.audience.InterfaceAudience;
 
+
 /**
  * Immutable POJO class for representing a table name.
  * Which is of the form:
@@ -53,6 +59,7 @@ import org.apache.yetus.audience.InterfaceAudience;
  */
 @InterfaceAudience.Public
 public final class TableName implements Comparable<TableName> {
+  private static final Log LOG = LogFactory.getLog(TableName.class);
 
   /** See {@link #createTableNameIfNecessary(ByteBuffer, ByteBuffer)} */
   private static final Set<TableName> tableCache = new CopyOnWriteArraySet<>();
@@ -76,9 +83,11 @@ public final class TableName implements Comparable<TableName> {
       "(?:(?:(?:"+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");
+  public static final String DEFAULT_META_TABLE_NAME_STR = "meta";
+  public static final String META_TABLE_SUFFIX = "hbase.meta.table.suffix";
+
+  /** The meta table's name. */
+  public static final TableName META_TABLE_NAME = getMetaTableName(HBaseConfiguration.create());
 
   /** The Namespace table's name. */
   public static final TableName NAMESPACE_TABLE_NAME =
@@ -535,4 +544,29 @@ public final class TableName implements Comparable<TableName> {
     return this.nameAsString.compareTo(tableName.getNameAsString());
   }
 
+  @VisibleForTesting
+  static TableName getMetaTableName(Configuration conf) {
+    String metaTableName = DEFAULT_META_TABLE_NAME_STR;
+    String metaTableSuffix = conf.get(META_TABLE_SUFFIX, "");
+
+    if(isValidMetaTableSuffix(metaTableSuffix)) {
+      metaTableName = DEFAULT_META_TABLE_NAME_STR + "_" + metaTableSuffix;
+    }
+    return (valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, metaTableName));
+  }
+
+  @VisibleForTesting
+  static boolean isValidMetaTableSuffix(String metaTableSuffix) {
+    if(StringUtils.isBlank(metaTableSuffix)) {
+      return false;
+    }
+
+    try {
+      isLegalTableQualifierName(Bytes.toBytes(metaTableSuffix));
+    } catch(IllegalArgumentException iae) {
+      LOG.warn("Invalid meta table suffix", iae);
+      return false;
+    }
+    return true;
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/0da6e5dd/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
----------------------------------------------------------------------
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 43a384a..d09ca8e 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
@@ -19,12 +19,15 @@ package org.apache.hadoop.hbase;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.Map;
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.testclassification.MiscTests;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -58,16 +61,19 @@ public class TestTableName extends TestWatcher {
     return tableName;
   }
 
-  String[] emptyNames = {"", " "};
-  String[] invalidNamespace = {":a", "%:a"};
-  String[] legalTableNames = {"foo", "with-dash_under.dot", "_under_start_ok",
-    "with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02",
-    "dot1.dot2.table", "new.-mytable", "with-dash.with.dot", "legal..t2", "legal..legal.t2",
-    "trailingdots..", "trailing.dots...", "ns:mytable", "ns:_mytable_", "ns:my_table_01-02"};
-  String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal", "spaces not ok",
-    "-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash",
-    "new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"};
-
+  String emptyNames[] ={"", " "};
+  String invalidNamespace[] = {":a", "%:a"};
+  String legalTableNames[] = { "foo", "with-dash_under.dot", "_under_start_ok",
+      "with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02"
+      , "dot1.dot2.table", "new.-mytable", "with-dash.with.dot", "legal..t2", "legal..legal.t2",
+      "trailingdots..", "trailing.dots...", "ns:mytable", "ns:_mytable_", "ns:my_table_01-02"};
+  String illegalTableNames[] = { ".dot_start_illegal", "-dash_start_illegal", "spaces not ok",
+      "-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash",
+      "new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"};
+  String legalMetaTableSuffixNames[] = { "foo", "with-dash_under.dot", "_under_start_ok",
+    "with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02"
+    , "dot1.dot2.table", "new.-mytable", "with-dash.with.dot", "legal..t2", "legal..legal.t2",
+    "trailingdots..", "trailing.dots..."};
 
   @Test(expected = IllegalArgumentException.class)
   public void testInvalidNamespace() {
@@ -191,6 +197,42 @@ public class TestTableName extends TestWatcher {
 
   }
 
+  @Test
+  public void testEmptyMetaTableSuffix() {
+    assertFalse(TableName.isValidMetaTableSuffix(null));
+    for (String tn : emptyNames) {
+      assertFalse(TableName.isValidMetaTableSuffix(tn));
+    }
+  }
+
+  @Test
+  public void testLegalMetaTableSuffix() {
+    for (String tn : legalMetaTableSuffixNames) {
+      assertTrue(TableName.isValidMetaTableSuffix(tn));
+    }
+  }
+
+  @Test
+  public void testIllegalMetaTableSuffix() {
+    for (String tn : illegalTableNames) {
+      assertFalse(TableName.isValidMetaTableSuffix(tn));
+    }
+  }
+
+  @Test
+  public void testMetaTableSuffixWithConfig() {
+    String metaTableNameWithSuffix = "hbase:meta_server1";
+    Configuration conf = new Configuration();
+
+    // without setting suffix, meta table name should be "hbase:meta"
+    assertEquals(TableName.getMetaTableName(conf).getNameAsString(), TableName.valueOf(
+      NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, TableName.DEFAULT_META_TABLE_NAME_STR)
+                                                                              .getNameAsString());
+
+    conf.set(TableName.META_TABLE_SUFFIX, "server1");
+    assertEquals(TableName.getMetaTableName(conf).getNameAsString(), metaTableNameWithSuffix);
+  }
+
   private TableName validateNames(TableName expected, Names names) {
     assertEquals(expected.getNameAsString(), names.nn);
     assertArrayEquals(expected.getName(), names.nnb);