From 49501cd5b5da439b646842350160bd42b9001b9e Mon Sep 17 00:00:00 2001 From: Toshihiro Suzuki Date: Tue, 21 Aug 2018 16:26:16 +0900 Subject: [PATCH] HBASE-21052 After restoring a snapshot, table.jsp page for the table gets stuck --- .../hadoop/hbase/client/HBaseAdmin.java | 9 +++++++- .../client/TestRestoreSnapshotFromClient.java | 23 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 8bc26f17e5c..b451c5a6ecc 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -3308,9 +3308,16 @@ public class HBaseAdmin implements Admin { @Override public CompactionState getCompactionState(final TableName tableName, CompactType compactType) throws IOException { + checkTableExists(tableName); + if (!isTableEnabled(tableName)) { + // If the table is disabled, the compaction state of the table should always be NONE + return ProtobufUtil.createCompactionState( + AdminProtos.GetRegionInfoResponse.CompactionState.NONE); + } + AdminProtos.GetRegionInfoResponse.CompactionState state = AdminProtos.GetRegionInfoResponse.CompactionState.NONE; - checkTableExists(tableName); + // TODO: There is no timeout on this controller. Set one! HBaseRpcController rpcController = rpcControllerFactory.newController(); switch (compactType) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java index 07044ee3793..138ec44e274 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java @@ -247,7 +247,8 @@ public class TestRestoreSnapshotFromClient { @Test public void testCloneSnapshotOfCloned() throws IOException, InterruptedException { - TableName clonedTableName = TableName.valueOf(name.getMethodName() + "-" + System.currentTimeMillis()); + TableName clonedTableName = TableName.valueOf(name.getMethodName() + "-" + + System.currentTimeMillis()); admin.cloneSnapshot(snapshotName0, clonedTableName); verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows); SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas()); @@ -282,7 +283,8 @@ public class TestRestoreSnapshotFromClient { @Test public void testCorruptedSnapshot() throws IOException, InterruptedException { SnapshotTestingUtils.corruptSnapshot(TEST_UTIL, Bytes.toString(snapshotName0)); - TableName cloneName = TableName.valueOf(name.getMethodName() + "-" + System.currentTimeMillis()); + TableName cloneName = TableName.valueOf(name.getMethodName() + "-" + + System.currentTimeMillis()); try { admin.cloneSnapshot(snapshotName0, cloneName); fail("Expected CorruptedSnapshotException, got succeeded cloneSnapshot()"); @@ -342,6 +344,23 @@ public class TestRestoreSnapshotFromClient { SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); } + @Test(timeout = 30000) + public void testGetCompactionStateAfterRestoringSnapshot() throws IOException, + InterruptedException { + // Take a snapshot + admin.snapshot(snapshotName1, tableName); + + // Restore the snapshot + admin.disableTable(tableName); + admin.restoreSnapshot(snapshotName1); + + // Get the compaction state of the restored table + CompactionState compactionState = admin.getCompactionState(tableName); + + // The compactionState should be NONE because the table is disabled + assertEquals(CompactionState.NONE, compactionState); + } + // ========================================================================== // Helpers // ==========================================================================