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:42:57 UTC

[2/3] hbase git commit: HBASE-18773 Add utility method to determine if a TableName is a meta table

HBASE-18773 Add utility method to determine if a TableName is a meta table

Signed-off-by: Michael Stack <st...@apache.org>


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

Branch: refs/heads/HBASE-18477
Commit: a748c8ba6bb43832b16deed2c5024388ba01a20e
Parents: 141bea4
Author: Zach York <zy...@amazon.com>
Authored: Wed Sep 6 17:48:05 2017 -0700
Committer: Zach York <zy...@apache.org>
Committed: Mon Jul 9 21:42:27 2018 -0700

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hbase/TableName.java |  4 +++
 .../util/ReadReplicaClustersTableNameUtil.java  | 35 ++++++++++++++++++
 .../org/apache/hadoop/hbase/TestTableName.java  |  8 +++++
 .../TestReadReplicaClustersTableNameUtil.java   | 37 ++++++++++++++++++++
 4 files changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/a748c8ba/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 7e68938..f796f33 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
@@ -569,4 +569,8 @@ public final class TableName implements Comparable<TableName> {
     }
     return true;
   }
+
+  public boolean isMeta() {
+    return isMetaTableName(this);
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/a748c8ba/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReadReplicaClustersTableNameUtil.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReadReplicaClustersTableNameUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReadReplicaClustersTableNameUtil.java
new file mode 100644
index 0000000..06db8fa
--- /dev/null
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ReadReplicaClustersTableNameUtil.java
@@ -0,0 +1,35 @@
+/**
+ * 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.util;
+
+import org.apache.hadoop.hbase.NamespaceDescriptor;
+import org.apache.hadoop.hbase.TableName;
+
+public class ReadReplicaClustersTableNameUtil {
+
+  /**
+   * Utility method to determine if TableName is a meta TableName without taking hbase.meta.table.suffix into account.
+   * @param tableName TableName to determine if isMeta
+   * @return if this TableName contains the default meta table name
+   */
+  public static boolean isMetaTableNameWithoutSuffix(TableName tableName) {
+    String[] parts = tableName.getNameWithNamespaceInclAsString().split(String.valueOf(TableName.NAMESPACE_DELIM));
+    return parts[0].equals(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR) &&
+        parts[1].startsWith(TableName.DEFAULT_META_TABLE_NAME_STR);
+  }
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/a748c8ba/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 d09ca8e..2ca1540 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
@@ -233,6 +233,14 @@ public class TestTableName extends TestWatcher {
     assertEquals(TableName.getMetaTableName(conf).getNameAsString(), metaTableNameWithSuffix);
   }
 
+  @Test
+  public void testIsMeta() {
+    String userTableContainingMeta = "default:meta";
+
+    assertTrue(TableName.META_TABLE_NAME.isMeta());
+    assertFalse(TableName.valueOf(userTableContainingMeta).isMeta());
+  }
+
   private TableName validateNames(TableName expected, Names names) {
     assertEquals(expected.getNameAsString(), names.nn);
     assertArrayEquals(expected.getName(), names.nnb);

http://git-wip-us.apache.org/repos/asf/hbase/blob/a748c8ba/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReadReplicaClustersTableNameUtil.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReadReplicaClustersTableNameUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReadReplicaClustersTableNameUtil.java
new file mode 100644
index 0000000..bde0202
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestReadReplicaClustersTableNameUtil.java
@@ -0,0 +1,37 @@
+/**
+ * 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.util;
+
+import org.apache.hadoop.hbase.TableName;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class TestReadReplicaClustersTableNameUtil {
+
+  @Test
+  public void testIsMetaTableNameWithoutSuffix() {
+    String metaWithSuffix = "hbase:meta_server1";
+    String userTableContainingMeta = "default:meta";
+
+    assertTrue(ReadReplicaClustersTableNameUtil.isMetaTableNameWithoutSuffix(TableName.META_TABLE_NAME));
+    assertTrue(ReadReplicaClustersTableNameUtil.isMetaTableNameWithoutSuffix(TableName.valueOf(metaWithSuffix)));
+    assertFalse(ReadReplicaClustersTableNameUtil.isMetaTableNameWithoutSuffix(TableName.valueOf(userTableContainingMeta)));
+  }
+}