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 0d09e6bf440 HDDS-16967. Fix flaky TestFailureHandlingByClient when a 
restarted Ratis follower lags (#11506)
0d09e6bf440 is described below

commit 0d09e6bf4407cc95e73bc0347ebbdb882a92c1ec
Author: Siyao Meng <[email protected]>
AuthorDate: Mon Oct 19 19:00:33 2026 -0700

    HDDS-16967. Fix flaky TestFailureHandlingByClient when a restarted Ratis 
follower lags (#11506)
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../client/rpc/TestFailureHandlingByClient.java    | 48 +++++++++++++++++++---
 .../hadoop/ozone/container/OzoneTestHelper.java    |  4 +-
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestFailureHandlingByClient.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestFailureHandlingByClient.java
index 632b45a5eee..4cc79a04cad 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestFailureHandlingByClient.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestFailureHandlingByClient.java
@@ -26,6 +26,7 @@
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 import java.io.IOException;
 import java.time.Duration;
@@ -55,6 +56,7 @@
 import org.apache.hadoop.ozone.MiniOzoneCluster;
 import org.apache.hadoop.ozone.OzoneConfigKeys;
 import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.RatisTestHelper;
 import org.apache.hadoop.ozone.client.ObjectStore;
 import org.apache.hadoop.ozone.client.OzoneClient;
 import org.apache.hadoop.ozone.client.OzoneClientFactory;
@@ -65,6 +67,7 @@
 import org.apache.hadoop.ozone.container.OzoneTestHelper;
 import org.apache.hadoop.ozone.container.common.helpers.BlockData;
 import org.apache.hadoop.ozone.container.common.interfaces.DBHandle;
+import 
org.apache.hadoop.ozone.container.common.transport.server.ratis.XceiverServerRatis;
 import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer;
 import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
 import org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils;
@@ -74,6 +77,8 @@
 import org.apache.ozone.test.GenericTestUtils;
 import org.apache.ozone.test.tag.Flaky;
 import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.protocol.RaftGroupId;
+import org.apache.ratis.server.RaftServer;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
@@ -159,8 +164,28 @@ public void restartDownDataNodes() throws Exception {
     for (DatanodeDetails dataNode : restartDataNodes) {
       cluster.restartHddsDatanode(dataNode, false);
     }
-    restartDataNodes.clear();
     cluster.waitForClusterToBeReady();
+    // A restarted datanode can take tens of seconds to rejoin its Ratis 
groups, while SCM keeps allocating
+    // blocks on those pipelines. Wait for every group on it to have a leader 
before the next test writes.
+    for (DatanodeDetails dataNode : restartDataNodes) {
+      RaftServer server = assertInstanceOf(XceiverServerRatis.class,
+          
cluster.getHddsDatanode(dataNode).getDatanodeStateMachine().getContainer().getWriteChannel()).getServer();
+      GenericTestUtils.waitFor(() -> allGroupsHaveLeader(server), 500, 
120_000);
+    }
+    restartDataNodes.clear();
+  }
+
+  private static boolean allGroupsHaveLeader(RaftServer server) {
+    try {
+      for (RaftGroupId groupId : server.getGroupIds()) {
+        if (server.getDivision(groupId).getInfo().getLeaderId() == null) {
+          return false;
+        }
+      }
+      return true;
+    } catch (IOException e) {
+      return false;
+    }
   }
 
   @AfterAll
@@ -196,10 +221,21 @@ public void testBlockWritesWithDnFailures() throws 
Exception {
           cluster.getStorageContainerManager().getPipelineManager()
               .getPipeline(container.getPipelineID());
       List<DatanodeDetails> datanodes = pipeline.getNodes();
-      cluster.shutdownHddsDatanode(datanodes.get(0));
-      cluster.shutdownHddsDatanode(datanodes.get(1));
-      restartDataNodes.add(datanodes.get(0));
-      restartDataNodes.add(datanodes.get(1));
+      // Keep the Ratis leader running. It has every entry the client counted 
as committed, while a lagging
+      // follower may not have the block at all, and the data must stay 
readable from the surviving replica.
+      DatanodeDetails leader = null;
+      for (DatanodeDetails dn : datanodes) {
+        if (RatisTestHelper.isRatisLeader(cluster.getHddsDatanode(dn), 
pipeline)) {
+          leader = dn;
+        }
+      }
+      assertNotNull(leader, "No Ratis leader found in pipeline " + 
pipeline.getId());
+      for (DatanodeDetails dn : datanodes) {
+        if (!dn.equals(leader)) {
+          cluster.shutdownHddsDatanode(dn);
+          restartDataNodes.add(dn);
+        }
+      }
       // The write will fail but exception will be handled and length will be
       // updated correctly in OzoneManager once the steam is closed
     }
@@ -263,7 +299,7 @@ private void testBlockCountOnFailures(OmKeyInfo omKeyInfo) 
throws Exception {
       block2ExpectedChunkCount = 2;
     }
 
-    // For the first block, first 2 DNs in the pipeline are shutdown (to
+    // For the first block, the 2 follower DNs in the pipeline are shutdown (to
     // simulate a failure). It should have 1 or 2 chunks (depending on
     // whether the DN CommitWatcher successfully acknowledged the 2nd chunk
     // write or not). The 3rd chunk would not exist on the first pipeline as
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/OzoneTestHelper.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/OzoneTestHelper.java
index 198d02106a3..6697ce816f5 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/OzoneTestHelper.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/OzoneTestHelper.java
@@ -361,9 +361,9 @@ public static void waitForContainerClose(MiniOzoneCluster 
cluster,
 
         // make sure the container gets created first
         assertFalse(isContainerClosed(cluster, containerID, details));
-        // send the order to close the container
-        scm.getEventQueue().fireEvent(SCMEvents.CLOSE_CONTAINER, 
ContainerID.valueOf(containerID));
       }
+      // Close only after every replica is checked: a lagging follower can 
apply the create and the close together.
+      scm.getEventQueue().fireEvent(SCMEvents.CLOSE_CONTAINER, 
ContainerID.valueOf(containerID));
     }
     int index = 0;
     for (long containerID : containerIdList) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to