You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2019/03/27 12:42:50 UTC
[hbase] branch branch-2.1 updated: HBASE-22094: Throw
TableNotFoundException if table not exists in AsyncAdmin.compact
This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 0d2c519 HBASE-22094: Throw TableNotFoundException if table not exists in AsyncAdmin.compact
0d2c519 is described below
commit 0d2c5197de43488509cf674d47177145cbc58c1a
Author: Sakthi <sa...@gmail.com>
AuthorDate: Mon Mar 25 22:54:48 2019 -0700
HBASE-22094: Throw TableNotFoundException if table not exists in AsyncAdmin.compact
Signed-off-by: zhangduo <zh...@apache.org>
---
.../org/apache/hadoop/hbase/client/AsyncAdmin.java | 12 ++++++++++++
.../hadoop/hbase/client/RawAsyncHBaseAdmin.java | 3 +++
.../hbase/client/TestAsyncRegionAdminApi.java | 21 +++++++++++++++++++++
3 files changed, 36 insertions(+)
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 134ef85..fe00df0 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
@@ -303,6 +303,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<Void> compact(TableName tableName) {
@@ -313,6 +314,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.
@@ -324,6 +326,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}
*/
@@ -333,6 +337,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}
@@ -360,6 +366,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<Void> majorCompact(TableName tableName) {
@@ -370,6 +377,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.
@@ -381,6 +390,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}
*/
@@ -390,6 +401,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 fa59751..e6bc918 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
@@ -1050,6 +1050,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 ef9714c..4e3c931 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
@@ -32,6 +32,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;
@@ -379,6 +380,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<Region> regions, final byte[] family) {
return countStoreFilesInFamilies(regions, new byte[][] { family });
}