Skip to content

Commit e992c03

Browse files
authored
HBASE-30259 Async WAL archiving causes TestMasterRegionWALCleaner flaky (apache#8417)
Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Xiao Liu <liuxiaocs@apache.org>
1 parent f49bda0 commit e992c03

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALCleaner.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
*/
1818
package org.apache.hadoop.hbase.master.region;
1919

20+
import static org.awaitility.Awaitility.await;
2021
import static org.junit.jupiter.api.Assertions.assertEquals;
2122
import static org.junit.jupiter.api.Assertions.assertFalse;
2223
import static org.junit.jupiter.api.Assertions.assertTrue;
2324

2425
import java.io.IOException;
26+
import java.time.Duration;
2527
import org.apache.hadoop.conf.Configuration;
2628
import org.apache.hadoop.fs.FileStatus;
2729
import org.apache.hadoop.fs.FileSystem;
@@ -82,14 +84,24 @@ public void test() throws IOException, InterruptedException {
8284
assertFalse(fs.exists(globalWALArchiveDir));
8385
region.requestRollAll();
8486
region.waitUntilWalRollFinished();
85-
// should have one
87+
// archiving wal is called in a background thread when rolling WALs, so it is possible that when
88+
// waitUntilWalRollFinished returns, the archived WAL files have not been moved to the global
89+
// archive directory yet, so here we need to wait for the directory to be created and the files
90+
// to be moved.
91+
await().atMost(Duration.ofSeconds(15)).untilAsserted(() -> {
92+
assertTrue(fs.exists(globalWALArchiveDir));
93+
assertEquals(1, fs.listStatus(globalWALArchiveDir).length);
94+
});
8695
FileStatus[] files = fs.listStatus(globalWALArchiveDir);
8796
assertEquals(1, files.length);
97+
// Rebase the WAL mtime so the following timing assertions are not affected by the wait above.
98+
// Cleaner TTL is based on file mtime.
99+
fs.setTimes(files[0].getPath(), System.currentTimeMillis(), -1);
88100
Thread.sleep(2000);
89101
// should still be there
90102
assertTrue(fs.exists(files[0].getPath()));
91-
Thread.sleep(6000);
92103
// should have been cleaned
93-
assertEquals(0, fs.listStatus(globalWALArchiveDir).length);
104+
await().atMost(Duration.ofSeconds(15))
105+
.untilAsserted(() -> assertEquals(0, fs.listStatus(globalWALArchiveDir).length));
94106
}
95107
}

0 commit comments

Comments
 (0)