This is an automated email from the ASF dual-hosted git repository.

SteNicholas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new 4fb63aa842 [CELEBORN-2532] Retry MasterClient when a full pass over 
master addresses fails
4fb63aa842 is described below

commit 4fb63aa8420ba27288a4c6dd29700d64c3ed9d4b
Author: shellfish007 <[email protected]>
AuthorDate: Sun Nov 8 12:37:54 2026 +0800

    [CELEBORN-2532] Retry MasterClient when a full pass over master addresses 
fails
    
    ### What changes were proposed in this pull request?
    
    Retry `MasterClient` requests when a full pass over the master addresses 
fails to connect to any of them.
    
    - `getOrSetupRpcEndpointRef` now throws `MasterUnavailableException`, a 
private `IllegalStateException` subclass, when one pass over all master 
addresses connects to none of them.
    - `shouldRetry` retries `MasterUnavailableException` within `maxRetries`, 
with the existing backoff. Other `IllegalStateException`s are still not retried.
    
    Once retries are exhausted, the caller still gets an 
`IllegalStateException` with the same message as before.
    
    JIRA: https://issues.apache.org/jira/browse/CELEBORN-2532
    
    ### Why are the changes needed?
    
    `getOrSetupRpcEndpointRef` swallows each connection failure in 
`setupEndpointRef` and moves to the next address, and throws 
`IllegalStateException` only after a full pass connects to none of them. 
`shouldRetry` doesn't retry it, so the caller fails after a single pass even 
though `maxRetries` would allow more attempts.
    
    This happens when the masters are briefly unreachable, e.g. while they are 
still starting or electing a leader. CELEBORN-2330 retries when a master 
redirects with a usable suggested leader, and CELEBORN-2369 retries a stopped 
outbox, but neither covers a pass where no master can be connected to.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No. Clients retry instead of failing on the first unsuccessful pass over 
the masters.
    
    ### How was this patch tested?
    
    `MasterClientSuiteJ`:
    - `testFailedPassOverAllMastersRetriesInHA`: the first pass fails to 
connect to all three masters, the next attempt connects, and the request 
succeeds.
    - `testFailedPassesOverAllMastersStopAfterMaxRetriesInHA`: when every pass 
fails, the client stops after `maxRetries` retried passes and throws 
`IllegalStateException`.
    
    Closes #3933 from 
shellfish007/upstream-pr/master-client-retry-illegal-state.
    
    Authored-by: shellfish007 <[email protected]>
    Signed-off-by: Nicholas Jiang <[email protected]>
---
 .../celeborn/common/client/MasterClient.java       | 15 +++++-
 .../celeborn/common/client/MasterClientSuiteJ.java | 62 ++++++++++++++++++++++
 2 files changed, 76 insertions(+), 1 deletion(-)

diff --git 
a/common/src/main/java/org/apache/celeborn/common/client/MasterClient.java 
b/common/src/main/java/org/apache/celeborn/common/client/MasterClient.java
index 252ad018a5..d5703d3401 100644
--- a/common/src/main/java/org/apache/celeborn/common/client/MasterClient.java
+++ b/common/src/main/java/org/apache/celeborn/common/client/MasterClient.java
@@ -189,6 +189,12 @@ public class MasterClient {
     } else if (isRetryableRpcFailure(e)) {
       resetRpcEndpointRef(oldRef);
       return true;
+    } else if (e instanceof MasterUnavailableException) {
+      // A full pass over the master addresses connected to none of them, e.g. 
while the masters
+      // are still starting or electing a leader. Retry within maxRetries 
instead of failing the
+      // caller on the first pass.
+      resetRpcEndpointRef(oldRef);
+      return true;
     }
     return false;
   }
@@ -317,7 +323,7 @@ public class MasterClient {
       currentIndex.set(index);
 
       if (endpointRef == null) {
-        throw new IllegalStateException(
+        throw new MasterUnavailableException(
             "After trying all the available Master Addresses("
                 + String.join(",", activeMasterEndpoints)
                 + "), an usable link still couldn't be created.");
@@ -355,4 +361,11 @@ public class MasterClient {
   public int getMaxRetries() {
     return maxRetries;
   }
+
+  /** Thrown when a full pass over the master addresses fails to connect to 
any of them. */
+  private static class MasterUnavailableException extends 
IllegalStateException {
+    MasterUnavailableException(String message) {
+      super(message);
+    }
+  }
 }
diff --git 
a/common/src/test/java/org/apache/celeborn/common/client/MasterClientSuiteJ.java
 
b/common/src/test/java/org/apache/celeborn/common/client/MasterClientSuiteJ.java
index e9781a9f4a..447306686f 100644
--- 
a/common/src/test/java/org/apache/celeborn/common/client/MasterClientSuiteJ.java
+++ 
b/common/src/test/java/org/apache/celeborn/common/client/MasterClientSuiteJ.java
@@ -413,6 +413,68 @@ public class MasterClientSuiteJ {
     assertEquals(mockResponse, response);
   }
 
+  @Test
+  public void testFailedPassOverAllMastersRetriesInHA() {
+    final CelebornConf conf = prepareForCelebornConfWithHA();
+
+    Mockito.doReturn(Future$.MODULE$.successful(mockResponse))
+        .when(endpointRef)
+        .ask(Mockito.any(), Mockito.any(), Mockito.any());
+
+    // The first pass fails to connect to all three masters, as while they are 
still starting.
+    final AtomicInteger numSetups = new AtomicInteger(0);
+    Mockito.doAnswer(
+            invocation -> {
+              if (numSetups.getAndIncrement() < 3) {
+                throw new IOException("Test IOException");
+              }
+              return endpointRef;
+            })
+        .when(rpcEnv)
+        .setupEndpointRef(Mockito.any(RpcAddress.class), Mockito.anyString());
+
+    MasterClient client = new MasterClient(rpcEnv, conf, false);
+    HeartbeatFromWorker message = Mockito.mock(HeartbeatFromWorker.class);
+
+    HeartbeatFromWorkerResponse response = null;
+    try {
+      response = client.askSync(message, HeartbeatFromWorkerResponse.class);
+    } catch (Throwable t) {
+      LOG.error("It should retry after a failed pass over all masters.", t);
+      fail("It should retry after a failed pass over all masters.");
+    }
+
+    assertEquals(mockResponse, response);
+    assertEquals(4, numSetups.get());
+  }
+
+  @Test
+  public void testFailedPassesOverAllMastersStopAfterMaxRetriesInHA() {
+    final CelebornConf conf = prepareForCelebornConfWithHA();
+
+    final AtomicInteger numSetups = new AtomicInteger(0);
+    Mockito.doAnswer(
+            invocation -> {
+              numSetups.incrementAndGet();
+              throw new IOException("Test IOException");
+            })
+        .when(rpcEnv)
+        .setupEndpointRef(Mockito.any(RpcAddress.class), Mockito.anyString());
+
+    MasterClient client = new MasterClient(rpcEnv, conf, false);
+    HeartbeatFromWorker message = Mockito.mock(HeartbeatFromWorker.class);
+
+    try {
+      client.askSync(message, HeartbeatFromWorkerResponse.class);
+      fail("It should fail after maxRetries failed passes over all masters.");
+    } catch (Throwable t) {
+      assertTrue(t instanceof IllegalStateException);
+    }
+
+    // One initial pass plus maxRetries retried passes, each over all three 
masters.
+    assertEquals((client.getMaxRetries() + 1) * 3, numSetups.get());
+  }
+
   @Test
   public void testSuggestedLeaderSetupFailureRetriesAnotherMasterInHA() {
     final CelebornConf conf =

Reply via email to