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 bce0327f2d0..d30a630a1e8 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 @@ -314,6 +314,7 @@ public interface AsyncAdmin { /** * Compact a table. When the returned CompletableFuture is done, it only means the compact request * was sent to HBase and may need some time to finish the compact operation. + * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found. * @param tableName table to compact */ default CompletableFuture compact(TableName tableName) { @@ -324,6 +325,7 @@ public interface AsyncAdmin { * Compact a column family within a table. When the returned CompletableFuture is done, it only * means the compact request was sent to HBase and may need some time to finish the compact * operation. + * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found. * @param tableName table to compact * @param columnFamily column family within a table. If not present, compact the table's all * column families. @@ -335,6 +337,8 @@ public interface AsyncAdmin { /** * Compact a table. When the returned CompletableFuture is done, it only means the compact request * was sent to HBase and may need some time to finish the compact operation. + * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for + * normal compaction type. * @param tableName table to compact * @param compactType {@link org.apache.hadoop.hbase.client.CompactType} */ @@ -344,6 +348,8 @@ public interface AsyncAdmin { * Compact a column family within a table. When the returned CompletableFuture is done, it only * means the compact request was sent to HBase and may need some time to finish the compact * operation. + * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for + * normal compaction type. * @param tableName table to compact * @param columnFamily column family within a table * @param compactType {@link org.apache.hadoop.hbase.client.CompactType} @@ -371,6 +377,7 @@ public interface AsyncAdmin { /** * Major compact a table. When the returned CompletableFuture is done, it only means the compact * request was sent to HBase and may need some time to finish the compact operation. + * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found. * @param tableName table to major compact */ default CompletableFuture majorCompact(TableName tableName) { @@ -381,6 +388,8 @@ public interface AsyncAdmin { * Major compact a column family within a table. When the returned CompletableFuture is done, it * only means the compact request was sent to HBase and may need some time to finish the compact * operation. + * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for + * normal compaction. type. * @param tableName table to major compact * @param columnFamily column family within a table. If not present, major compact the table's all * column families. @@ -392,6 +401,8 @@ public interface AsyncAdmin { /** * Major compact a table. When the returned CompletableFuture is done, it only means the compact * request was sent to HBase and may need some time to finish the compact operation. + * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found for + * normal compaction type. * @param tableName table to major compact * @param compactType {@link org.apache.hadoop.hbase.client.CompactType} */ @@ -401,6 +412,7 @@ public interface AsyncAdmin { * Major compact a column family within a table. When the returned CompletableFuture is done, it * only means the compact request was sent to HBase and may need some time to finish the compact * operation. + * Throws {@link org.apache.hadoop.hbase.TableNotFoundException} if table not found. * @param tableName table to major compact * @param columnFamily column family within a table. If not present, major compact the table's all * column families. 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 42152ce94ed..85662b164a9 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 @@ -1103,6 +1103,9 @@ class RawAsyncHBaseAdmin implements AsyncAdmin { future.completeExceptionally(err); return; } + if (locations == null || locations.isEmpty()) { + future.completeExceptionally(new TableNotFoundException(tableName)); + } CompletableFuture[] compactFutures = locations.stream().filter(l -> l.getRegion() != null) .filter(l -> !l.getRegion().isOffline()).filter(l -> l.getServerName() != null) 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 6d30faf6248..3a8673cfba3 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 @@ -36,6 +36,7 @@ import java.util.stream.Collectors; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.hbase.master.ServerManager; @@ -427,6 +428,26 @@ public class TestAsyncRegionAdminApi extends TestAsyncAdminBase { } } + @Test + public void testNonExistentTableCompaction() { + testNonExistentTableCompaction(CompactionState.MINOR); + testNonExistentTableCompaction(CompactionState.MAJOR); + } + + private void testNonExistentTableCompaction(CompactionState compactionState) { + try { + if (compactionState == CompactionState.MINOR) { + admin.compact(TableName.valueOf("NonExistentTable")).get(); + } else { + admin.majorCompact(TableName.valueOf("NonExistentTable")).get(); + } + fail("Expected TableNotFoundException when table doesn't exist"); + } catch (Exception e) { + // expected. + assertTrue(e.getCause() instanceof TableNotFoundException); + } + } + private static int countStoreFilesInFamily(List regions, final byte[] family) { return countStoreFilesInFamilies(regions, new byte[][] { family }); }