Skip to content

Commit 3f25794

Browse files
committed
[fix][dingo-sdk] Added preWrite to the problem of leader switching, reporting an error instead of SDK side retry
1 parent e96a80c commit 3f25794

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

java/dingo-sdk/src/main/java/io/dingodb/sdk/common/utils/ErrorCodeUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,10 @@ public static Strategy errorToStrategy(int code) {
9090
return Strategy.FAILED;
9191
}
9292

93+
public static boolean isPreWriteRequestFailed(int code, boolean isPreWrite) {
94+
return isPreWrite && (code == ERAFT_NOTLEADER_VALUE || code == ERAFT_COMMITLOG_VALUE);
95+
}
96+
97+
9398
public static final Function<Integer, Strategy> errorToStrategyFunc = ErrorCodeUtils::errorToStrategy;
9499
}

java/dingo-sdk/src/main/java/io/dingodb/sdk/service/caller/ServiceCaller.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.dingodb.sdk.common.DingoClientException.ExhaustedRetryException;
44
import io.dingodb.sdk.common.DingoClientException.InvalidRouteTableException;
55
import io.dingodb.sdk.common.DingoClientException.RequestErrorException;
6+
import io.dingodb.sdk.common.utils.ErrorCodeUtils;
67
import io.dingodb.sdk.service.JsonMessageUtils;
78
import io.dingodb.sdk.service.Caller;
89
import io.dingodb.sdk.service.ChannelProvider;
@@ -12,6 +13,7 @@
1213
import io.dingodb.sdk.service.entity.Message.Response;
1314
import io.dingodb.sdk.service.entity.error.Errno;
1415
import io.dingodb.sdk.service.entity.error.Error;
16+
import io.dingodb.sdk.service.entity.store.TxnPrewriteResponse;
1517
import io.grpc.CallOptions;
1618
import io.grpc.Channel;
1719
import io.grpc.MethodDescriptor;
@@ -25,6 +27,7 @@
2527
import java.util.function.Function;
2628

2729
import static io.dingodb.sdk.common.utils.ErrorCodeUtils.errorToStrategy;
30+
import static io.dingodb.sdk.common.utils.ErrorCodeUtils.isPreWriteRequestFailed;
2831

2932
@Slf4j
3033
public class ServiceCaller<S extends Service<S>> implements Caller<S> {
@@ -97,7 +100,8 @@ public <REQ extends Request, RES extends Response> RES call(
97100
channel.authority() + ">>" + error.getErrmsg(), (k, v) -> v == null ? 1 : v + 1
98101
);
99102
switch (handler.onErrStrategy(
100-
errorToStrategy(errCode),
103+
isPreWriteRequestFailed(errCode, (response instanceof TxnPrewriteResponse)) ?
104+
ErrorCodeUtils.Strategy.FAILED : errorToStrategy(errCode),
101105
this.retry, retry, request, response, options, channel.authority(), requestId
102106
)) {
103107
case RETRY:
@@ -123,7 +127,8 @@ public <REQ extends Request, RES extends Response> RES call(
123127
handler.onIgnore(request, response, options, channel.authority(), requestId);
124128
return null;
125129
default:
126-
throw new IllegalStateException("Unexpected value: " + errorToStrategy(errCode));
130+
throw new IllegalStateException("Unexpected value: " + errorToStrategy(
131+
errCode));
127132
}
128133
}
129134
handler.after(request, response, options, channel.authority(), requestId);

0 commit comments

Comments
 (0)