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

dragonyliu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 46501e584 RATIS-1744. NullPointerException causes RaftClient retry 
failure. (#794)
46501e584 is described below

commit 46501e58423a43c5068835fbd95289f622e4cfab
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Sun Dec 4 05:20:39 2022 -0800

    RATIS-1744. NullPointerException causes RaftClient retry failure. (#794)
    
    * RATIS-1744. NullPointerException causes RaftClient retry failure.
    
    * Use ReadIndexException
---
 .../src/main/java/org/apache/ratis/grpc/GrpcUtil.java    | 16 ++++++++--------
 .../org/apache/ratis/server/impl/RaftServerImpl.java     |  8 ++++----
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcUtil.java 
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcUtil.java
index 57673c991..23e8a8261 100644
--- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcUtil.java
+++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcUtil.java
@@ -86,20 +86,20 @@ public interface GrpcUtil {
 
   static Throwable unwrapThrowable(Throwable t) {
     if (t instanceof StatusRuntimeException) {
-      final IOException ioe = tryUnwrapException((StatusRuntimeException)t);
-      if (ioe != null) {
-        return ioe;
+      final Throwable unwrapped = 
tryUnwrapThrowable((StatusRuntimeException)t);
+      if (unwrapped != null) {
+        return unwrapped;
       }
     }
     return t;
   }
 
   static IOException unwrapException(StatusRuntimeException se) {
-    final IOException ioe = tryUnwrapException(se);
-    return ioe != null? ioe: new IOException(se);
+    final Throwable t = tryUnwrapThrowable(se);
+    return t instanceof IOException? (IOException) t: new IOException(t != 
null? t: se);
   }
 
-  static IOException tryUnwrapException(StatusRuntimeException se) {
+  static Throwable tryUnwrapThrowable(StatusRuntimeException se) {
     final Status status = se.getStatus();
     if (status != null && status.getCode() == Status.Code.DEADLINE_EXCEEDED) {
       return new TimeoutIOException(status.getDescription(), se);
@@ -113,7 +113,7 @@ public interface GrpcUtil {
     final byte[] bytes = trailers.get(EXCEPTION_OBJECT_KEY);
     if (bytes != null) {
       try {
-        return IOUtils.bytes2Object(bytes, IOException.class);
+        return IOUtils.bytes2Object(bytes, Throwable.class);
       } catch (Exception e) {
         se.addSuppressed(e);
       }
@@ -125,7 +125,7 @@ public interface GrpcUtil {
         try {
           final Class<? extends Throwable> clazz = 
Class.forName(className).asSubclass(Throwable.class);
           final Throwable unwrapped = 
ReflectionUtils.instantiateException(clazz, status.getDescription());
-          return IOUtils.asIOException(unwrapped.initCause(se));
+          return unwrapped.initCause(se);
         } catch (Throwable e) {
           se.addSuppressed(e);
           return new IOException(se);
diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
index 1265d7a9b..d7a577feb 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
@@ -921,11 +921,11 @@ class RaftServerImpl implements RaftServer.Division,
   }
 
   private CompletableFuture<ReadIndexReplyProto> sendReadIndexAsync() {
-    if (getInfo().getLeaderId() == null) {
-      JavaUtils.completeExceptionally(generateNotLeaderException());
+    final RaftPeerId leaderId = getInfo().getLeaderId();
+    if (leaderId == null) {
+      return JavaUtils.completeExceptionally(new 
ReadIndexException(getMemberId() + ": Leader is unknown."));
     }
-    final ReadIndexRequestProto request = 
ServerProtoUtils.toReadIndexRequestProto(
-        getMemberId(),  getInfo().getLeaderId());
+    final ReadIndexRequestProto request = 
ServerProtoUtils.toReadIndexRequestProto(getMemberId(), leaderId);
     try {
       return getServerRpc().async().readIndexAsync(request);
     } catch (IOException e) {

Reply via email to