HBASE-22094: Throw TableNotFoundException if table not exists in AsyncAdmin.compact

Signed-off-by: zhangduo <zhangduo@apache.org>
This commit is contained in:
Sakthi 2019-03-25 22:54:48 -07:00 committed by zhangduo
parent 56dd309b21
commit caa9650a70
3 changed files with 36 additions and 0 deletions

View File

@ -306,6 +306,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) {
@ -316,6 +317,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.
@ -327,6 +329,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}
*/
@ -336,6 +340,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}
@ -363,6 +369,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) {
@ -373,6 +380,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.
@ -384,6 +393,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}
*/
@ -393,6 +404,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.

View File

@ -1099,6 +1099,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)

View File

@ -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<Region> regions, final byte[] family) {
return countStoreFilesInFamilies(regions, new byte[][] { family });
}