You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celeborn.apache.org by re...@apache.org on 2023/10/11 12:25:08 UTC

[incubator-celeborn] branch branch-0.3 updated: [CELEBORN-1033] MasterNotLeaderException should provide the cause of exception

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

rexxiong pushed a commit to branch branch-0.3
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git


The following commit(s) were added to refs/heads/branch-0.3 by this push:
     new 25c7f448c [CELEBORN-1033] MasterNotLeaderException should provide the cause of exception
25c7f448c is described below

commit 25c7f448c0a24431476cf9ceaf72dad787b9e2dc
Author: SteNicholas <pr...@163.com>
AuthorDate: Wed Oct 11 20:18:58 2023 +0800

    [CELEBORN-1033] MasterNotLeaderException should provide the cause of exception
    
    `HAHelper#sendFailure` only sends `MasterNotLeaderException` without cause, which causes that the actual exception of `MasterNotLeaderException` could not catch for troubleshooting.
    
    `MasterNotLeaderException` provides the cause of exception.
    
    No.
    
    `MasterClientSuiteJ`
    
    Closes #1972 from SteNicholas/CELEBORN-1033.
    
    Authored-by: SteNicholas <pr...@163.com>
    Signed-off-by: Shuang <lv...@gmail.com>
    (cherry picked from commit 84a318f71644b3ebcca0627e25fc459ad230db58)
    Signed-off-by: Shuang <lv...@gmail.com>
---
 .../common/client/MasterNotLeaderException.java    | 25 ++++++++++++++--------
 .../celeborn/common/client/MasterClientSuiteJ.java |  8 ++-----
 .../deploy/master/clustermeta/ha/HAHelper.java     |  7 ++++--
 3 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/common/src/main/java/org/apache/celeborn/common/client/MasterNotLeaderException.java b/common/src/main/java/org/apache/celeborn/common/client/MasterNotLeaderException.java
index 10c3c24ea..6502f44db 100644
--- a/common/src/main/java/org/apache/celeborn/common/client/MasterNotLeaderException.java
+++ b/common/src/main/java/org/apache/celeborn/common/client/MasterNotLeaderException.java
@@ -19,22 +19,29 @@ package org.apache.celeborn.common.client;
 
 import java.io.IOException;
 
+import javax.annotation.Nullable;
+
+import org.apache.commons.lang3.StringUtils;
+
 public class MasterNotLeaderException extends IOException {
 
-  private final String currentPeer;
+  private static final long serialVersionUID = -2552475565785098271L;
+
   private final String leaderPeer;
 
   public static final String LEADER_NOT_PRESENTED = "leader is not present";
 
-  public MasterNotLeaderException(String currentPeer, String suggestedLeaderPeer) {
+  public MasterNotLeaderException(
+      String currentPeer, String suggestedLeaderPeer, @Nullable Throwable cause) {
     super(
-        "Master:"
-            + currentPeer
-            + " is not the leader. Suggested leader is"
-            + " Master:"
-            + suggestedLeaderPeer
-            + ".");
-    this.currentPeer = currentPeer;
+        String.format(
+            "Master:%s is not the leader. Suggested leader is Master:%s.%s",
+            currentPeer,
+            suggestedLeaderPeer,
+            cause == null
+                ? StringUtils.EMPTY
+                : String.format(" Exception:%s.", cause.getMessage())),
+        cause);
     this.leaderPeer = suggestedLeaderPeer;
   }
 
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 3f0b86992..4a84f7c5f 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
@@ -227,9 +227,7 @@ public class MasterClientSuiteJ {
 
     // master leader switch to host2
     Mockito.doReturn(
-            Future$.MODULE$.failed(
-                new org.apache.celeborn.common.haclient.MasterNotLeaderException(
-                    "host1:9097", "host2:9097")))
+            Future$.MODULE$.failed(new MasterNotLeaderException("host1:9097", "host2:9097", null)))
         .when(master1)
         .ask(Mockito.any(), Mockito.any(), Mockito.any());
 
@@ -277,9 +275,7 @@ public class MasterClientSuiteJ {
 
     // master leader switch to host2
     Mockito.doReturn(
-            Future$.MODULE$.failed(
-                new org.apache.celeborn.common.haclient.MasterNotLeaderException(
-                    "host1:9097", "host2:9097")))
+            Future$.MODULE$.failed(new MasterNotLeaderException("host1:9097", "host2:9097", null)))
         .when(ref1)
         .ask(Mockito.any(), Mockito.any(), Mockito.any());
     // Assume host2 down.
diff --git a/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/HAHelper.java b/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/HAHelper.java
index 570c09d53..eb1209609 100644
--- a/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/HAHelper.java
+++ b/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/HAHelper.java
@@ -55,11 +55,14 @@ public class HAHelper {
           context.sendFailure(
               new MasterNotLeaderException(
                   ratisServer.getRpcEndpoint(),
-                  ratisServer.getCachedLeaderPeerRpcEndpoint().get()));
+                  ratisServer.getCachedLeaderPeerRpcEndpoint().get(),
+                  cause));
         } else {
           context.sendFailure(
               new MasterNotLeaderException(
-                  ratisServer.getRpcEndpoint(), MasterNotLeaderException.LEADER_NOT_PRESENTED));
+                  ratisServer.getRpcEndpoint(),
+                  MasterNotLeaderException.LEADER_NOT_PRESENTED,
+                  cause));
         }
       } else {
         context.sendFailure(new CelebornIOException(cause.getMessage(), cause));