This is an automated email from the ASF dual-hosted git repository.
smengcl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 891b158ea2b HDDS-16598. Fix intermittent failure in
TestContainerStateMachine (#11319)
891b158ea2b is described below
commit 891b158ea2bd1fba7ba368b6f3bb890b12e7757f
Author: Shuo Huang <[email protected]>
AuthorDate: Thu Oct 8 02:58:25 2026 +0800
HDDS-16598. Fix intermittent failure in TestContainerStateMachine (#11319)
---
.../client/rpc/TestContainerStateMachine.java | 47 +++++++++++-----------
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestContainerStateMachine.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestContainerStateMachine.java
index 9790af8217f..95bf599bde8 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestContainerStateMachine.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestContainerStateMachine.java
@@ -23,13 +23,10 @@
import static
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_CONTAINER_REPORT_INTERVAL;
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_INTERVAL;
import static
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.File;
import java.io.IOException;
-import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -57,8 +54,11 @@
import
org.apache.hadoop.ozone.container.common.transport.server.ratis.RatisServerConfiguration;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.ozone.test.GenericTestUtils;
import org.apache.ratis.statemachine.impl.SimpleStateMachineStorage;
+import org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo;
import org.apache.ratis.statemachine.impl.StatemachineImplTestUtil;
+import org.apache.ratis.util.function.CheckedSupplier;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -169,7 +169,9 @@ public void testRatisSnapshotRetention() throws Exception {
(ContainerStateMachine) OzoneTestHelper.getStateMachine(cluster);
SimpleStateMachineStorage storage =
(SimpleStateMachineStorage) stateMachine.getStateMachineStorage();
- assertNull(StatemachineImplTestUtil.findLatestSnapshot(storage));
+ long lastAppliedIndex = stateMachine.getLastAppliedTermIndex().getIndex();
+ int retainedSnapshots = conf.getObject(RatisServerConfiguration.class)
+ .getNumSnapshotsRetained();
// Write 10 keys. Num snapshots should be equal to config value.
for (int i = 1; i <= 10; i++) {
@@ -185,18 +187,10 @@ public void testRatisSnapshotRetention() throws Exception
{
}
}
- RatisServerConfiguration ratisServerConfiguration =
- conf.getObject(RatisServerConfiguration.class);
-
- Path parentPath = getSnapshotPath(storage).getParent();
- assertThat(parentPath).isNotNull();
- File[] files = parentPath.toFile().listFiles();
- assertThat(files).isNotNull();
- int numSnapshots = files.length;
- assertThat(Math.abs(ratisServerConfiguration.getNumSnapshotsRetained() -
numSnapshots))
- .isLessThanOrEqualTo(1);
+ waitForSnapshotRetention(storage, lastAppliedIndex, retainedSnapshots);
// Write 10 more keys. Num Snapshots should remain the same.
+ lastAppliedIndex = stateMachine.getLastAppliedTermIndex().getIndex();
for (int i = 11; i <= 20; i++) {
try (OzoneOutputStream key =
objectStore.getVolume(volumeName).getBucket(bucketName)
@@ -209,16 +203,23 @@ public void testRatisSnapshotRetention() throws Exception
{
key.write(("ratis" + i).getBytes(UTF_8));
}
}
- files = parentPath.toFile().listFiles();
- assertThat(files).isNotNull();
- numSnapshots = files.length;
- assertThat(Math.abs(ratisServerConfiguration.getNumSnapshotsRetained() -
numSnapshots))
- .isLessThanOrEqualTo(1);
+ waitForSnapshotRetention(storage, lastAppliedIndex, retainedSnapshots);
}
- static Path getSnapshotPath(SimpleStateMachineStorage storage)
- throws IOException {
- return StatemachineImplTestUtil.findLatestSnapshot(storage)
- .getFile().getPath();
+ private static void waitForSnapshotRetention(
+ SimpleStateMachineStorage storage, long index, int retainedSnapshots)
+ throws Exception {
+ CheckedSupplier<Boolean, IOException> retentionSatisfied = () -> {
+ SingleFileSnapshotInfo snapshot =
+ StatemachineImplTestUtil.findLatestSnapshot(storage);
+ if (snapshot == null || snapshot.getTermIndex().getIndex() <= index) {
+ return false;
+ }
+ File[] files = snapshot.getFile().getPath().getParent().toFile()
+ .listFiles();
+ return files != null
+ && Math.abs(retainedSnapshots - files.length) <= 1;
+ };
+ GenericTestUtils.waitFor(retentionSatisfied, 100, 30_000);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]