HBASE-21705 Should treat meta table specially for some methods in AsyncAdmin

This commit is contained in:
zhangduo 2019-01-12 18:18:29 +08:00
parent 3d2580cd6d
commit c5691a9f60
3 changed files with 52 additions and 19 deletions

View File

@ -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);
}

View File

@ -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) {

View File

@ -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());
}
}