From e08ac5fafb3e80a13f13c31ba80c87562fda0c2c Mon Sep 17 00:00:00 2001 From: linkaline Date: Thu, 18 Jul 2019 09:02:17 +0800 Subject: [PATCH] HBASE-21426 TestEncryptionKeyRotation.testCFKeyRotation is flaky (#375) Signed-off-by: Guanghao Zhang --- .../TestEncryptionKeyRotation.java | 53 +++---------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java index 3a212f881611..230e74936cd2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java @@ -35,7 +35,8 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.Waiter.Predicate; +import org.apache.hadoop.hbase.Waiter; +import org.apache.hadoop.hbase.client.CompactionState; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.io.crypto.Encryption; @@ -133,27 +134,14 @@ public void testCFKeyRotation() throws Exception { // And major compact TEST_UTIL.getAdmin().majorCompact(htd.getTableName()); - final List updatePaths = findCompactedStorefilePaths(htd.getTableName()); - TEST_UTIL.waitFor(30000, 1000, true, new Predicate() { + // waiting for the major compaction to complete + TEST_UTIL.waitFor(30000, new Waiter.Predicate() { @Override - public boolean evaluate() throws Exception { - // When compaction has finished, all of the original files will be - // gone - boolean found = false; - for (Path path: updatePaths) { - found = TEST_UTIL.getTestFileSystem().exists(path); - if (found) { - LOG.info("Found " + path); - break; - } - } - return !found; + public boolean evaluate() throws IOException { + return TEST_UTIL.getAdmin().getCompactionState(htd.getTableName()) == + CompactionState.NONE; } }); - - // Verify we have store file(s) with only the new key - Thread.sleep(1000); - waitForCompaction(htd.getTableName()); List pathsAfterCompaction = findStorefilePaths(htd.getTableName()); assertTrue(pathsAfterCompaction.size() > 0); for (Path path: pathsAfterCompaction) { @@ -210,33 +198,6 @@ public void testMasterKeyRotation() throws Exception { } } - private static void waitForCompaction(TableName tableName) - throws IOException, InterruptedException { - boolean compacted = false; - for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName) - .getRegions(tableName)) { - for (HStore store : ((HRegion) region).getStores()) { - compacted = false; - while (!compacted) { - if (store.getStorefiles() != null) { - while (store.getStorefilesCount() != 1) { - Thread.sleep(100); - } - for (HStoreFile storefile : store.getStorefiles()) { - if (!storefile.isCompactedAway()) { - compacted = true; - break; - } - Thread.sleep(100); - } - } else { - break; - } - } - } - } - } - private static List findStorefilePaths(TableName tableName) throws Exception { List paths = new ArrayList<>(); for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName)