You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2023/05/21 15:18:50 UTC

[iotdb] branch master updated: IOTDB-5848] Allow ratis-client retry when gRPC IO Unavailable (#9898)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7c9299f7b37 IOTDB-5848] Allow ratis-client retry when gRPC IO Unavailable (#9898)
7c9299f7b37 is described below

commit 7c9299f7b374af789ce529169beeac3a6891158d
Author: William Song <48...@users.noreply.github.com>
AuthorDate: Sun May 21 23:18:44 2023 +0800

    IOTDB-5848] Allow ratis-client retry when gRPC IO Unavailable (#9898)
---
 .../org/apache/iotdb/consensus/ratis/RatisClient.java  | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisClient.java b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisClient.java
index 9e870338f5e..fe80a486062 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisClient.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisClient.java
@@ -31,11 +31,13 @@ import org.apache.ratis.protocol.RaftGroup;
 import org.apache.ratis.protocol.exceptions.RaftException;
 import org.apache.ratis.retry.ExponentialBackoffRetry;
 import org.apache.ratis.retry.RetryPolicy;
+import org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException;
 import org.apache.ratis.util.TimeDuration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
 class RatisClient {
@@ -141,10 +143,18 @@ class RatisClient {
 
     @Override
     public Action handleAttemptFailure(Event event) {
-
-      if (event.getCause() instanceof IOException && !(event.getCause() instanceof RaftException)) {
-        // unexpected. may be caused by statemachine.
-        logger.info("raft client request failed and caught exception: ", event.getCause());
+      // Ratis guarantees that event.getCause() is instance of IOException.
+      // We should allow RaftException or IOException(StatusRuntimeException, thrown by gRPC) to be
+      // retried.
+      Optional<Throwable> unexpectedCause =
+          Optional.ofNullable(event.getCause())
+              .filter(t -> t instanceof RaftException)
+              .map(Throwable::getCause)
+              .filter(t -> t instanceof StatusRuntimeException);
+
+      if (unexpectedCause.isPresent()) {
+        logger.info(
+            "{}: raft client request failed and caught exception: ", this, unexpectedCause.get());
         return NO_RETRY_ACTION;
       }