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 13245d377aa..5d38179fabb 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 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 b3cd17f3675..762a920d01c 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 @@ -405,6 +405,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin { @Override public CompletableFuture tableExists(TableName tableName) { + if (TableName.isMetaTableName(tableName)) { + return CompletableFuture.completedFuture(true); + } return AsyncMetaTableAccessor.tableExists(metaTable, tableName); } @@ -584,6 +587,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin { @Override public CompletableFuture isTableEnabled(TableName tableName) { + if (TableName.isMetaTableName(tableName)) { + return CompletableFuture.completedFuture(true); + } CompletableFuture future = new CompletableFuture<>(); addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> { if (error != null) { @@ -601,6 +607,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin { @Override public CompletableFuture isTableDisabled(TableName tableName) { + if (TableName.isMetaTableName(tableName)) { + return CompletableFuture.completedFuture(false); + } CompletableFuture future = new CompletableFuture<>(); addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> { if (error != null) { @@ -630,6 +639,10 @@ class RawAsyncHBaseAdmin implements AsyncAdmin { private CompletableFuture isTableAvailable(TableName tableName, Optional splitKeys) { + if (TableName.isMetaTableName(tableName)) { + return connection.registry.getMetaRegionLocation().thenApply(locs -> Stream + .of(locs.getRegionLocations()).allMatch(loc -> loc != null && loc.getServerName() != null)); + } CompletableFuture 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 07c8d774a54..750749dc0e1 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(); - assertEquals(true, exist); + assertTrue(exist); + // meta table already exists + exist = admin.tableExists(TableName.META_TABLE_NAME).get(); + 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()); } }