This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 6d7afec RATIS-601. Fix NotLeaderException handling. Contributed by
Mukul Kumar Singh
6d7afec is described below
commit 6d7afecf4ec547815e283602f6ba2bac73b165cc
Author: Tsz Wo Nicholas Sze <[email protected]>
AuthorDate: Sun Jun 23 07:01:23 2019 +0800
RATIS-601. Fix NotLeaderException handling. Contributed by Mukul Kumar
Singh
---
.../src/main/java/org/apache/ratis/client/impl/OrderedAsync.java | 7 ++++++-
.../src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java | 6 ++++--
.../src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java | 5 ++---
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git
a/ratis-client/src/main/java/org/apache/ratis/client/impl/OrderedAsync.java
b/ratis-client/src/main/java/org/apache/ratis/client/impl/OrderedAsync.java
index 1f22a1e..3800439 100644
--- a/ratis-client/src/main/java/org/apache/ratis/client/impl/OrderedAsync.java
+++ b/ratis-client/src/main/java/org/apache/ratis/client/impl/OrderedAsync.java
@@ -232,7 +232,12 @@ class OrderedAsync {
if (!retryPolicy.shouldRetry(attemptCount, request)) {
handleAsyncRetryFailure(request, attemptCount, e);
} else {
- client.handleIOException(request, (IOException) e, null,
this::resetSlidingWindow);
+ if (e instanceof NotLeaderException) {
+ NotLeaderException nle = (NotLeaderException)e;
+ client.handleNotLeaderException(request, nle,
this::resetSlidingWindow);
+ } else {
+ client.handleIOException(request, (IOException) e, null,
this::resetSlidingWindow);
+ }
}
if (e instanceof NotLeaderException) {
throw new CompletionException(e);
diff --git
a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
index a280b15..34bce9e 100644
---
a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
+++
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
@@ -364,12 +364,14 @@ final class RaftClientImpl implements RaftClient {
}
LOG.debug("{}: oldLeader={}, curLeader={}, newLeader={}", clientId,
oldLeader, curLeader, newLeader);
- final boolean changeLeader = newLeader != null && stillLeader;
+ final boolean changeLeader = !(ioe instanceof AlreadyClosedException ||
ioe instanceof TimeoutIOException)
+ && newLeader != null && stillLeader;
final boolean reconnect = changeLeader || clientRpc.shouldReconnect(ioe);
if (reconnect) {
try(AutoCloseableLock writeLock = writeLock()) {
if (changeLeader && oldLeader.equals(leaderId)) {
- LOG.debug("{}: change Leader from {} to {}", clientId, oldLeader,
newLeader);
+ LOG.debug("{} {}: client change Leader from {} to {} ex={}", groupId,
+ clientId, oldLeader, newLeader, ioe.getClass().getName());
this.leaderId = newLeader;
}
clientRpc.handleException(oldLeader, ioe, reconnect);
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 ecd790d..ec21a17 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
@@ -451,9 +451,8 @@ public class RaftServerImpl implements RaftServerProtocol,
RaftServerAsynchronou
RaftPeerId leaderId = state.getLeaderId();
if (leaderId == null || leaderId.equals(state.getSelfId())) {
// No idea about who is the current leader. Or the peer is the current
- // leader, but it is about to step down
- RaftPeer suggestedLeader =
getRaftConf().getRandomPeer(state.getSelfId());
- leaderId = suggestedLeader == null ? null : suggestedLeader.getId();
+ // leader, but it is about to step down. set the suggested leader as
null.
+ leaderId = null;
}
RaftConfiguration conf = getRaftConf();
Collection<RaftPeer> peers = conf.getPeers();