hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject hbase git commit: HBASE-18773 Add utility method to determine if a TableName is a meta table
Date Wed, 20 Sep 2017 22:47:35 GMT
Repository: hbase
Updated Branches:
  refs/heads/HBASE-18477 b5f1850d1 -> 4b2a0976e


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

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


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

Branch: refs/heads/HBASE-18477
Commit: 4b2a0976e9d8d6790a11be46731b46953489ca17
Parents: b5f1850
Author: Zach York <zyork@amazon.com>
Authored: Wed Sep 6 17:48:05 2017 -0700
Committer: Michael Stack <stack@apache.org>
Committed: Wed Sep 20 15:43:16 2017 -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/4b2a0976/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 e838146..4278158 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
@@ -586,4 +586,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/4b2a0976/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/4b2a0976/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 69f9014..657f90e 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
@@ -219,6 +219,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/4b2a0976/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)));
+  }
+}


Mime
View raw message