From 58b0585d66b90d3cdf47da84c64f2912e1773934 Mon Sep 17 00:00:00 2001 From: Guanghao Zhang Date: Mon, 16 Oct 2017 17:12:37 +0800 Subject: [PATCH] HBASE-18914 Remove AsyncAdmin's methods which were already deprecated in Admin interface --- .../hadoop/hbase/client/AsyncAdmin.java | 54 -------------- .../hadoop/hbase/client/AsyncHBaseAdmin.java | 25 ------- .../hbase/client/RawAsyncHBaseAdmin.java | 65 ----------------- .../hbase/client/TestAsyncRegionAdminApi.java | 70 ------------------- .../client/TestAsyncSnapshotAdminApi.java | 11 ++- .../hbase/client/TestAsyncTableAdminApi.java | 25 ++----- 6 files changed, 9 insertions(+), 241 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java index e539c6a201d..0a88138067b 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java @@ -142,17 +142,6 @@ public interface AsyncAdmin { */ CompletableFuture deleteTable(TableName tableName); - /** - * Delete tables matching the passed in pattern and wait on completion. Warning: Use this method - * carefully, there is no prompting and the effect is immediate. Consider using - * {@link #listTableNames(Optional, boolean) } and - * {@link #deleteTable(org.apache.hadoop.hbase.TableName)} - * @param pattern The pattern to match table names against - * @return Table descriptors for tables that couldn't be deleted. The return value will be wrapped - * by a {@link CompletableFuture}. The return HTDs are read-only. - */ - CompletableFuture> deleteTables(Pattern pattern); - /** * Truncate a table. * @param tableName name of table to truncate @@ -166,32 +155,12 @@ public interface AsyncAdmin { */ CompletableFuture enableTable(TableName tableName); - /** - * Enable tables matching the passed in pattern. Warning: Use this method carefully, there is no - * prompting and the effect is immediate. Consider using {@link #listTables(Optional, boolean)} and - * {@link #enableTable(TableName)} - * @param pattern The pattern to match table names against - * @return Table descriptors for tables that couldn't be enabled. The return value will be wrapped - * by a {@link CompletableFuture}. The return HTDs are read-only. - */ - CompletableFuture> enableTables(Pattern pattern); - /** * Disable a table. The table has to be in enabled state for it to be disabled. * @param tableName */ CompletableFuture disableTable(TableName tableName); - /** - * Disable tables matching the passed in pattern. Warning: Use this method carefully, there is no - * prompting and the effect is immediate. Consider using {@link #listTables(Optional, boolean)} and - * {@link #disableTable(TableName)} - * @param pattern The pattern to match table names against - * @return Table descriptors for tables that couldn't be disabled. The return value will be wrapped by a - * {@link CompletableFuture}. The return HTDs are read-only. - */ - CompletableFuture> disableTables(Pattern pattern); - /** * @param tableName name of table to check * @return true if table is on-line. The return value will be wrapped by a @@ -225,16 +194,6 @@ public interface AsyncAdmin { */ CompletableFuture isTableAvailable(TableName tableName, byte[][] splitKeys); - /** - * Get the status of alter command - indicates how many regions have received the updated schema - * Asynchronous operation. - * @param tableName TableName instance - * @return Pair indicating the number of regions updated Pair.getFirst() is the regions that are - * yet to be updated Pair.getSecond() is the total number of regions of the table. The - * return value will be wrapped by a {@link CompletableFuture}. - */ - CompletableFuture> getAlterStatus(TableName tableName); - /** * Add a column family to an existing table. * @param tableName name of the table to add column family to @@ -289,19 +248,6 @@ public interface AsyncAdmin { */ CompletableFuture> listNamespaceDescriptors(); - /** - * Close a region. For expert-admins Runs close on the regionserver. The master will not be - * informed of the close. - * @param regionName region name to close - * @param serverName Deprecated. Not used anymore after deprecation. - * @return Deprecated. Always returns true now. - * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0 - * (HBASE-18231). - * Use {@link #unassign(byte[], boolean)}. - */ - @Deprecated - CompletableFuture closeRegion(byte[] regionName, Optional serverName); - /** * Get all the online regions on a region server. */ diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java index 3cb8360781c..f60f7ea824a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java @@ -116,11 +116,6 @@ public class AsyncHBaseAdmin implements AsyncAdmin { return wrap(rawAdmin.deleteTable(tableName)); } - @Override - public CompletableFuture> deleteTables(Pattern pattern) { - return wrap(rawAdmin.deleteTables(pattern)); - } - @Override public CompletableFuture truncateTable(TableName tableName, boolean preserveSplits) { return wrap(rawAdmin.truncateTable(tableName, preserveSplits)); @@ -131,21 +126,11 @@ public class AsyncHBaseAdmin implements AsyncAdmin { return wrap(rawAdmin.enableTable(tableName)); } - @Override - public CompletableFuture> enableTables(Pattern pattern) { - return wrap(rawAdmin.enableTables(pattern)); - } - @Override public CompletableFuture disableTable(TableName tableName) { return wrap(rawAdmin.disableTable(tableName)); } - @Override - public CompletableFuture> disableTables(Pattern pattern) { - return wrap(rawAdmin.disableTables(pattern)); - } - @Override public CompletableFuture isTableEnabled(TableName tableName) { return wrap(rawAdmin.isTableEnabled(tableName)); @@ -161,11 +146,6 @@ public class AsyncHBaseAdmin implements AsyncAdmin { return wrap(rawAdmin.isTableAvailable(tableName, splitKeys)); } - @Override - public CompletableFuture> getAlterStatus(TableName tableName) { - return wrap(rawAdmin.getAlterStatus(tableName)); - } - @Override public CompletableFuture addColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily) { @@ -208,11 +188,6 @@ public class AsyncHBaseAdmin implements AsyncAdmin { return wrap(rawAdmin.listNamespaceDescriptors()); } - @Override - public CompletableFuture closeRegion(byte[] regionName, Optional unused) { - return wrap(rawAdmin.closeRegion(regionName, unused)); - } - @Override public CompletableFuture> getOnlineRegions(ServerName serverName) { return wrap(rawAdmin.getOnlineRegions(serverName)); 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 589796a8d07..597acd3fab7 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 @@ -383,31 +383,6 @@ public class RawAsyncHBaseAdmin implements AsyncAdmin { CompletableFuture operate(TableName table); } - private CompletableFuture> batchTableOperations(Pattern pattern, - TableOperator operator, String operationType) { - CompletableFuture> future = new CompletableFuture<>(); - List failed = new LinkedList<>(); - listTables(Optional.ofNullable(pattern), false).whenComplete( - (tables, error) -> { - if (error != null) { - future.completeExceptionally(error); - return; - } - CompletableFuture[] futures = - tables.stream() - .map((table) -> operator.operate(table.getTableName()).whenComplete((v, ex) -> { - if (ex != null) { - LOG.info("Failed to " + operationType + " table " + table.getTableName(), ex); - failed.add(table); - } - })). toArray(size -> new CompletableFuture[size]); - CompletableFuture.allOf(futures).thenAccept((v) -> { - future.complete(failed); - }); - }); - return future; - } - @Override public CompletableFuture tableExists(TableName tableName) { return AsyncMetaTableAccessor.tableExists(metaTable, tableName); @@ -495,11 +470,6 @@ public class RawAsyncHBaseAdmin implements AsyncAdmin { new DeleteTableProcedureBiConsumer(this, tableName)); } - @Override - public CompletableFuture> deleteTables(Pattern pattern) { - return batchTableOperations(pattern, (table) -> deleteTable(table), "DELETE"); - } - @Override public CompletableFuture truncateTable(TableName tableName, boolean preserveSplits) { return this. procedureCall( @@ -516,11 +486,6 @@ public class RawAsyncHBaseAdmin implements AsyncAdmin { new EnableTableProcedureBiConsumer(this, tableName)); } - @Override - public CompletableFuture> enableTables(Pattern pattern) { - return batchTableOperations(pattern, (table) -> enableTable(table), "ENABLE"); - } - @Override public CompletableFuture disableTable(TableName tableName) { return this. procedureCall(RequestConverter @@ -529,11 +494,6 @@ public class RawAsyncHBaseAdmin implements AsyncAdmin { new DisableTableProcedureBiConsumer(this, tableName)); } - @Override - public CompletableFuture> disableTables(Pattern pattern) { - return batchTableOperations(pattern, (table) -> disableTable(table), "DISABLE"); - } - @Override public CompletableFuture isTableEnabled(TableName tableName) { CompletableFuture future = new CompletableFuture<>(); @@ -640,18 +600,6 @@ public class RawAsyncHBaseAdmin implements AsyncAdmin { return future; } - @Override - public CompletableFuture> getAlterStatus(TableName tableName) { - return this - .>newMasterCaller() - .action( - (controller, stub) -> this - .> call( - controller, stub, RequestConverter.buildGetSchemaAlterStatusRequest(tableName), (s, - c, req, done) -> s.getSchemaAlterStatus(c, req, done), (resp) -> new Pair<>( - resp.getYetToUpdateRegions(), resp.getTotalRegions()))).call(); - } - @Override public CompletableFuture addColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily) { return this. procedureCall( @@ -725,19 +673,6 @@ public class RawAsyncHBaseAdmin implements AsyncAdmin { .toNamespaceDescriptorList(resp))).call(); } - @Override - public CompletableFuture closeRegion(byte[] regionName, Optional unused) { - CompletableFuture future = new CompletableFuture<>(); - unassign(regionName, true).whenComplete((result, err) -> { - if (err != null) { - future.completeExceptionally(err); - } else { - future.complete(true); - } - }); - return future; - } - @Override public CompletableFuture> getOnlineRegions(ServerName serverName) { return this.> newAdminCaller() diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java index f63516fb47d..262cac62540 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionAdminApi.java @@ -56,8 +56,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; - /** * Class to test asynchronous region admin operations. */ @@ -65,74 +63,6 @@ import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; @Category({ LargeTests.class, ClientTests.class }) public class TestAsyncRegionAdminApi extends TestAsyncAdminBase { - @Test - public void testCloseRegion() throws Exception { - createTableWithDefaultConf(tableName); - - RegionInfo info = null; - HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName); - List onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); - for (RegionInfo regionInfo : onlineRegions) { - if (!regionInfo.getTable().isSystemTable()) { - info = regionInfo; - boolean closed = admin.closeRegion(regionInfo.getRegionName(), - Optional.of(rs.getServerName())).get(); - assertTrue(closed); - } - } - boolean isInList = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()).contains(info); - long timeout = System.currentTimeMillis() + 10000; - while ((System.currentTimeMillis() < timeout) && (isInList)) { - Thread.sleep(100); - isInList = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()).contains(info); - } - - assertFalse("The region should not be present in online regions list.", isInList); - } - - @Test - public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception { - createTableWithDefaultConf(tableName); - - RegionInfo info = null; - HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName); - List onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); - for (RegionInfo regionInfo : onlineRegions) { - if (!regionInfo.isMetaRegion()) { - if (regionInfo.getRegionNameAsString().contains(tableName.getNameAsString())) { - info = regionInfo; - boolean catchNotServingException = false; - try { - admin.closeRegion(Bytes.toBytes("sample"), Optional.of(rs.getServerName())) - .get(); - } catch (Exception e) { - catchNotServingException = true; - // expected, ignore it - } - assertTrue(catchNotServingException); - } - } - } - onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); - assertTrue("The region should be present in online regions list.", - onlineRegions.contains(info)); - } - - @Test - public void testCloseRegionWhenServerNameIsEmpty() throws Exception { - createTableWithDefaultConf(tableName); - - HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName); - List onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); - for (RegionInfo regionInfo : onlineRegions) { - if (!regionInfo.isMetaRegion()) { - if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegionWhenServerNameIsEmpty")) { - admin.closeRegion(regionInfo.getRegionName(), Optional.empty()).get(); - } - } - } - } - @Test public void testGetRegionLocation() throws Exception { RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncSnapshotAdminApi.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncSnapshotAdminApi.java index 19931d0e706..f789da5f98c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncSnapshotAdminApi.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncSnapshotAdminApi.java @@ -24,11 +24,8 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.After; import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -42,15 +39,17 @@ import java.util.regex.Pattern; @Category({ LargeTests.class, ClientTests.class }) public class TestAsyncSnapshotAdminApi extends TestAsyncAdminBase { + private static final Pattern MATCH_ALL = Pattern.compile(".*"); + String snapshotName1 = "snapshotName1"; String snapshotName2 = "snapshotName2"; String snapshotName3 = "snapshotName3"; @After public void cleanup() throws Exception { - admin.deleteSnapshots(Pattern.compile(".*")).get(); - admin.disableTables(Pattern.compile(".*")).get(); - admin.deleteTables(Pattern.compile(".*")).get(); + admin.deleteSnapshots(MATCH_ALL).get(); + admin.listTableNames().get().forEach(t -> admin.disableTable(t).join()); + admin.listTableNames().get().forEach(t -> admin.deleteTable(t).join()); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java index e8d338d7fca..4df594749f2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableAdminApi.java @@ -406,25 +406,6 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase { assertFalse(admin.tableExists(tableName).get()); } - @Test - public void testDeleteTables() throws Exception { - TableName[] tables = - { TableName.valueOf(tableName.getNameAsString() + "1"), - TableName.valueOf(tableName.getNameAsString() + "2"), - TableName.valueOf(tableName.getNameAsString() + "3") }; - Arrays.stream(tables).forEach((table) -> { - createTableWithDefaultConf(table); - admin.tableExists(table).thenAccept((exist) -> assertTrue(exist)).join(); - admin.disableTable(table).join(); - }); - List failed = - admin.deleteTables(Pattern.compile(tableName.getNameAsString() + ".*")).get(); - assertEquals(0, failed.size()); - Arrays.stream(tables).forEach((table) -> { - admin.tableExists(table).thenAccept((exist) -> assertFalse(exist)).join(); - }); - } - @Test public void testTruncateTable() throws Exception { testTruncateTable(tableName, false); @@ -536,7 +517,8 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase { table1.get(get).get(); table2.get(get).get(); - this.admin.disableTables(Pattern.compile(tableName.getNameAsString() + ".*")).join(); + admin.listTableNames(Optional.of(Pattern.compile(tableName.getNameAsString() + ".*")), false) + .get().forEach(t -> admin.disableTable(t).join()); // Test that tables are disabled get = new Get(row); @@ -559,7 +541,8 @@ public class TestAsyncTableAdminApi extends TestAsyncAdminBase { assertEquals(TableState.State.DISABLED, getStateFromMeta(tableName1)); assertEquals(TableState.State.DISABLED, getStateFromMeta(tableName2)); - this.admin.enableTables(Pattern.compile("testDisableAndEnableTables.*")).join(); + admin.listTableNames(Optional.of(Pattern.compile(tableName.getNameAsString() + ".*")), false) + .get().forEach(t -> admin.enableTable(t).join()); // Test that tables are enabled try {