hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhang...@apache.org
Subject [hbase] branch master updated: HBASE-21705 Should treat meta table specially for some methods in AsyncAdmin
Date Sun, 13 Jan 2019 05:48:02 GMT
This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/master by this push:
     new c5691a9  HBASE-21705 Should treat meta table specially for some methods in AsyncAdmin
c5691a9 is described below

commit c5691a9f602a04ae2e010a90c8ab61aeb764405e
Author: zhangduo <zhangduo@apache.org>
AuthorDate: Sat Jan 12 18:18:29 2019 +0800

    HBASE-21705 Should treat meta table specially for some methods in AsyncAdmin
---
 .../hadoop/hbase/AsyncMetaTableAccessor.java       |  6 ---
 .../hadoop/hbase/client/RawAsyncHBaseAdmin.java    | 13 ++++++
 .../hbase/client/TestAsyncTableAdminApi3.java      | 52 ++++++++++++++++------
 3 files changed, 52 insertions(+), 19 deletions(-)

diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/AsyncMetaTableAccessor.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/AsyncMetaTableAccessor.java
index 13245d3..5d38179 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/AsyncMetaTableAccessor.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/AsyncMetaTableAccessor.java
@@ -17,8 +17,6 @@
  */
 package org.apache.hadoop.hbase;
 
-import static org.apache.hadoop.hbase.TableName.META_TABLE_NAME;
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -32,7 +30,6 @@ import java.util.concurrent.CompletableFuture;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
-
 import org.apache.hadoop.hbase.MetaTableAccessor.CollectingVisitor;
 import org.apache.hadoop.hbase.MetaTableAccessor.QueryType;
 import org.apache.hadoop.hbase.MetaTableAccessor.Visitor;
@@ -74,9 +71,6 @@ public class AsyncMetaTableAccessor {
 
   public static CompletableFuture<Boolean> tableExists(AsyncTable<?> metaTable,
       TableName tableName) {
-    if (tableName.equals(META_TABLE_NAME)) {
-      return CompletableFuture.completedFuture(true);
-    }
     return getTableState(metaTable, tableName).thenApply(Optional::isPresent);
   }
 
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
index 1440a64..08a202b 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java
@@ -415,6 +415,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
 
   @Override
   public CompletableFuture<Boolean> tableExists(TableName tableName) {
+    if (TableName.isMetaTableName(tableName)) {
+      return CompletableFuture.completedFuture(true);
+    }
     return AsyncMetaTableAccessor.tableExists(metaTable, tableName);
   }
 
@@ -594,6 +597,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
 
   @Override
   public CompletableFuture<Boolean> isTableEnabled(TableName tableName) {
+    if (TableName.isMetaTableName(tableName)) {
+      return CompletableFuture.completedFuture(true);
+    }
     CompletableFuture<Boolean> future = new CompletableFuture<>();
     addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error)
-> {
       if (error != null) {
@@ -611,6 +617,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
 
   @Override
   public CompletableFuture<Boolean> isTableDisabled(TableName tableName) {
+    if (TableName.isMetaTableName(tableName)) {
+      return CompletableFuture.completedFuture(false);
+    }
     CompletableFuture<Boolean> future = new CompletableFuture<>();
     addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error)
-> {
       if (error != null) {
@@ -640,6 +649,10 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
 
   private CompletableFuture<Boolean> isTableAvailable(TableName tableName,
       Optional<byte[][]> splitKeys) {
+    if (TableName.isMetaTableName(tableName)) {
+      return connection.registry.getMetaRegionLocation().thenApply(locs -> Stream
+        .of(locs.getRegionLocations()).allMatch(loc -> loc != null && loc.getServerName()
!= null));
+    }
     CompletableFuture<Boolean> future = new CompletableFuture<>();
     addListener(isTableEnabled(tableName), (enabled, error) -> {
       if (error != null) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi3.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi3.java
index 07c8d77..750749d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi3.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi3.java
@@ -17,7 +17,20 @@
  */
 package org.apache.hadoop.hbase.client;
 
+import static org.apache.hadoop.hbase.TableName.META_TABLE_NAME;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import java.util.regex.Pattern;
 import org.apache.hadoop.hbase.AsyncMetaTableAccessor;
+import org.apache.hadoop.hbase.DoNotRetryIOException;
 import org.apache.hadoop.hbase.HBaseClassTestRule;
 import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.TableName;
@@ -31,16 +44,6 @@ import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import java.util.regex.Pattern;
-
-import static org.apache.hadoop.hbase.TableName.META_TABLE_NAME;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 /**
  * Class to test asynchronous table admin operations.
  * @see TestAsyncTableAdminApi2 This test and it used to be joined it was taking longer than
our
@@ -57,12 +60,15 @@ public class TestAsyncTableAdminApi3 extends TestAsyncAdminBase {
   public void testTableExist() throws Exception {
     boolean exist;
     exist = admin.tableExists(tableName).get();
-    assertEquals(false, exist);
+    assertFalse(exist);
     TEST_UTIL.createTable(tableName, FAMILY);
     exist = admin.tableExists(tableName).get();
-    assertEquals(true, exist);
+    assertTrue(exist);
+    exist = admin.tableExists(TableName.META_TABLE_NAME).get();
+    assertTrue(exist);
+    // meta table already exists
     exist = admin.tableExists(TableName.META_TABLE_NAME).get();
-    assertEquals(true, exist);
+    assertTrue(exist);
   }
 
   @Test
@@ -177,6 +183,14 @@ public class TestAsyncTableAdminApi3 extends TestAsyncAdminBase {
       ok = false;
     }
     assertTrue(ok);
+    // meta table can not be disabled.
+    try {
+      admin.disableTable(TableName.META_TABLE_NAME).get();
+      fail("meta table can not be disabled");
+    } catch (ExecutionException e) {
+      Throwable cause = e.getCause();
+      assertThat(cause, instanceOf(DoNotRetryIOException.class));
+    }
   }
 
   @Test
@@ -278,5 +292,17 @@ public class TestAsyncTableAdminApi3 extends TestAsyncAdminBase {
     admin.disableTable(tableName).join();
     assertFalse(admin.isTableEnabled(tableName).get());
     assertTrue(admin.isTableDisabled(tableName).get());
+
+    // meta table is always enabled
+    assertTrue(admin.isTableEnabled(TableName.META_TABLE_NAME).get());
+    assertFalse(admin.isTableDisabled(TableName.META_TABLE_NAME).get());
+  }
+
+  @Test
+  public void testIsTableAvailable() throws Exception {
+    createTableWithDefaultConf(tableName);
+    TEST_UTIL.waitTableAvailable(tableName);
+    assertTrue(admin.isTableAvailable(tableName).get());
+    assertTrue(admin.isTableAvailable(TableName.META_TABLE_NAME).get());
   }
 }


Mime
View raw message