Skip to content

Commit e08ac5f

Browse files
sunhellyinfraio
authored andcommitted
HBASE-21426 TestEncryptionKeyRotation.testCFKeyRotation is flaky (#375)
Signed-off-by: Guanghao Zhang <zghao@apache.org>
1 parent f0cbdf8 commit e08ac5f

File tree

1 file changed

+7
-46
lines changed

1 file changed

+7
-46
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import org.apache.hadoop.hbase.HConstants;
3636
import org.apache.hadoop.hbase.HTableDescriptor;
3737
import org.apache.hadoop.hbase.TableName;
38-
import org.apache.hadoop.hbase.Waiter.Predicate;
38+
import org.apache.hadoop.hbase.Waiter;
39+
import org.apache.hadoop.hbase.client.CompactionState;
3940
import org.apache.hadoop.hbase.client.Put;
4041
import org.apache.hadoop.hbase.client.Table;
4142
import org.apache.hadoop.hbase.io.crypto.Encryption;
@@ -133,27 +134,14 @@ public void testCFKeyRotation() throws Exception {
133134

134135
// And major compact
135136
TEST_UTIL.getAdmin().majorCompact(htd.getTableName());
136-
final List<Path> updatePaths = findCompactedStorefilePaths(htd.getTableName());
137-
TEST_UTIL.waitFor(30000, 1000, true, new Predicate<Exception>() {
137+
// waiting for the major compaction to complete
138+
TEST_UTIL.waitFor(30000, new Waiter.Predicate<IOException>() {
138139
@Override
139-
public boolean evaluate() throws Exception {
140-
// When compaction has finished, all of the original files will be
141-
// gone
142-
boolean found = false;
143-
for (Path path: updatePaths) {
144-
found = TEST_UTIL.getTestFileSystem().exists(path);
145-
if (found) {
146-
LOG.info("Found " + path);
147-
break;
148-
}
149-
}
150-
return !found;
140+
public boolean evaluate() throws IOException {
141+
return TEST_UTIL.getAdmin().getCompactionState(htd.getTableName()) ==
142+
CompactionState.NONE;
151143
}
152144
});
153-
154-
// Verify we have store file(s) with only the new key
155-
Thread.sleep(1000);
156-
waitForCompaction(htd.getTableName());
157145
List<Path> pathsAfterCompaction = findStorefilePaths(htd.getTableName());
158146
assertTrue(pathsAfterCompaction.size() > 0);
159147
for (Path path: pathsAfterCompaction) {
@@ -210,33 +198,6 @@ public void testMasterKeyRotation() throws Exception {
210198
}
211199
}
212200

213-
private static void waitForCompaction(TableName tableName)
214-
throws IOException, InterruptedException {
215-
boolean compacted = false;
216-
for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName)
217-
.getRegions(tableName)) {
218-
for (HStore store : ((HRegion) region).getStores()) {
219-
compacted = false;
220-
while (!compacted) {
221-
if (store.getStorefiles() != null) {
222-
while (store.getStorefilesCount() != 1) {
223-
Thread.sleep(100);
224-
}
225-
for (HStoreFile storefile : store.getStorefiles()) {
226-
if (!storefile.isCompactedAway()) {
227-
compacted = true;
228-
break;
229-
}
230-
Thread.sleep(100);
231-
}
232-
} else {
233-
break;
234-
}
235-
}
236-
}
237-
}
238-
}
239-
240201
private static List<Path> findStorefilePaths(TableName tableName) throws Exception {
241202
List<Path> paths = new ArrayList<>();
242203
for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName)

0 commit comments

Comments
 (0)