HBASE-21705 Should treat meta table specially for some methods in AsyncAdmin
This commit is contained in:
parent
d7db78b74c
commit
b26bcb852c
|
@ -17,8 +17,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase;
|
package org.apache.hadoop.hbase;
|
||||||
|
|
||||||
import static org.apache.hadoop.hbase.TableName.META_TABLE_NAME;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -32,7 +30,6 @@ import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.MetaTableAccessor.CollectingVisitor;
|
import org.apache.hadoop.hbase.MetaTableAccessor.CollectingVisitor;
|
||||||
import org.apache.hadoop.hbase.MetaTableAccessor.QueryType;
|
import org.apache.hadoop.hbase.MetaTableAccessor.QueryType;
|
||||||
import org.apache.hadoop.hbase.MetaTableAccessor.Visitor;
|
import org.apache.hadoop.hbase.MetaTableAccessor.Visitor;
|
||||||
|
@ -74,9 +71,6 @@ public class AsyncMetaTableAccessor {
|
||||||
|
|
||||||
public static CompletableFuture<Boolean> tableExists(AsyncTable<?> metaTable,
|
public static CompletableFuture<Boolean> tableExists(AsyncTable<?> metaTable,
|
||||||
TableName tableName) {
|
TableName tableName) {
|
||||||
if (tableName.equals(META_TABLE_NAME)) {
|
|
||||||
return CompletableFuture.completedFuture(true);
|
|
||||||
}
|
|
||||||
return getTableState(metaTable, tableName).thenApply(Optional::isPresent);
|
return getTableState(metaTable, tableName).thenApply(Optional::isPresent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -405,6 +405,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> tableExists(TableName tableName) {
|
public CompletableFuture<Boolean> tableExists(TableName tableName) {
|
||||||
|
if (TableName.isMetaTableName(tableName)) {
|
||||||
|
return CompletableFuture.completedFuture(true);
|
||||||
|
}
|
||||||
return AsyncMetaTableAccessor.tableExists(metaTable, tableName);
|
return AsyncMetaTableAccessor.tableExists(metaTable, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,6 +587,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> isTableEnabled(TableName tableName) {
|
public CompletableFuture<Boolean> isTableEnabled(TableName tableName) {
|
||||||
|
if (TableName.isMetaTableName(tableName)) {
|
||||||
|
return CompletableFuture.completedFuture(true);
|
||||||
|
}
|
||||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> {
|
addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
@ -601,6 +607,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> isTableDisabled(TableName tableName) {
|
public CompletableFuture<Boolean> isTableDisabled(TableName tableName) {
|
||||||
|
if (TableName.isMetaTableName(tableName)) {
|
||||||
|
return CompletableFuture.completedFuture(false);
|
||||||
|
}
|
||||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> {
|
addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
@ -630,6 +639,10 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
|
|
||||||
private CompletableFuture<Boolean> isTableAvailable(TableName tableName,
|
private CompletableFuture<Boolean> isTableAvailable(TableName tableName,
|
||||||
Optional<byte[][]> splitKeys) {
|
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<>();
|
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
addListener(isTableEnabled(tableName), (enabled, error) -> {
|
addListener(isTableEnabled(tableName), (enabled, error) -> {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
|
|
@ -17,7 +17,20 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.client;
|
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.AsyncMetaTableAccessor;
|
||||||
|
import org.apache.hadoop.hbase.DoNotRetryIOException;
|
||||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
import org.apache.hadoop.hbase.HRegionLocation;
|
import org.apache.hadoop.hbase.HRegionLocation;
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
|
@ -31,16 +44,6 @@ import org.junit.experimental.categories.Category;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
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.
|
* Class to test asynchronous table admin operations.
|
||||||
* @see TestAsyncTableAdminApi2 This test and it used to be joined it was taking longer than our
|
* @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 {
|
public void testTableExist() throws Exception {
|
||||||
boolean exist;
|
boolean exist;
|
||||||
exist = admin.tableExists(tableName).get();
|
exist = admin.tableExists(tableName).get();
|
||||||
assertEquals(false, exist);
|
assertFalse(exist);
|
||||||
TEST_UTIL.createTable(tableName, FAMILY);
|
TEST_UTIL.createTable(tableName, FAMILY);
|
||||||
exist = admin.tableExists(tableName).get();
|
exist = admin.tableExists(tableName).get();
|
||||||
assertEquals(true, exist);
|
assertTrue(exist);
|
||||||
exist = admin.tableExists(TableName.META_TABLE_NAME).get();
|
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
|
@Test
|
||||||
|
@ -177,6 +183,14 @@ public class TestAsyncTableAdminApi3 extends TestAsyncAdminBase {
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
assertTrue(ok);
|
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
|
@Test
|
||||||
|
@ -278,5 +292,17 @@ public class TestAsyncTableAdminApi3 extends TestAsyncAdminBase {
|
||||||
admin.disableTable(tableName).join();
|
admin.disableTable(tableName).join();
|
||||||
assertFalse(admin.isTableEnabled(tableName).get());
|
assertFalse(admin.isTableEnabled(tableName).get());
|
||||||
assertTrue(admin.isTableDisabled(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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue