From b0c6de7f89041b8ba5415c45046890061e9cb10c Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Fri, 31 Jul 2026 22:49:37 +0800 Subject: [PATCH] HDFS-17956. Bound TestBackupNode.waitCheckpointDone with timeout Replace the unbounded do-while polling loop in waitCheckpointDone with GenericTestUtils.waitFor, capping at 60s. The loop previously slept indefinitely when a checkpoint never arrived, hanging the surefire fork until the 900s forkedProcessTimeoutInSeconds killed it, causing the consistent 'hdfs - other' CI failures on trunk since late July. Assisted-by: GLM 5.2 --- .../hdfs/server/namenode/TestBackupNode.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBackupNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBackupNode.java index fbaca9442742fa..3b4fd38d8ccd09 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBackupNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestBackupNode.java @@ -116,18 +116,15 @@ BackupNode startBackupNode(Configuration conf, return bn; } - void waitCheckpointDone(MiniDFSCluster cluster, long txid) { - long thisCheckpointTxId; - do { - try { - LOG.info("Waiting checkpoint to complete... " + - "checkpoint txid should increase above " + txid); - Thread.sleep(1000); - } catch (Exception e) {} - // The checkpoint is not done until the nn has received it from the bn - thisCheckpointTxId = cluster.getNameNode().getFSImage().getStorage() + void waitCheckpointDone(MiniDFSCluster cluster, long txid) + throws Exception { + GenericTestUtils.waitFor( + () -> cluster.getNameNode().getFSImage().getStorage() + .getMostRecentCheckpointTxId() >= txid, + 1000, 60000, + "Checkpoint txid did not advance above " + txid); + long thisCheckpointTxId = cluster.getNameNode().getFSImage().getStorage() .getMostRecentCheckpointTxId(); - } while (thisCheckpointTxId < txid); // Check that the checkpoint got uploaded to NN successfully FSImageTestUtil.assertNNHasCheckpoints(cluster, Collections.singletonList((int)thisCheckpointTxId)); @@ -504,7 +501,7 @@ void testCheckpoint(StartupOption op) throws Exception { * Verify that a file can be read both from NameNode and BackupNode. */ @Test - public void testCanReadData() throws IOException { + public void testCanReadData() throws Exception { Path file1 = new Path("/fileToRead.dat"); Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null;