You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by wi...@apache.org on 2023/08/28 08:55:22 UTC
[ratis] 02/10: RATIS-1861. NullPointerException in readAsync when Ratis leader is changing (#895)
This is an automated email from the ASF dual-hosted git repository.
williamsong pushed a commit to branch snapshot-branch2
in repository https://gitbox.apache.org/repos/asf/ratis.git
commit 1d07f9faf947e99e0680834541f5aa2731b806e0
Author: Xiangpeng Hu <65...@users.noreply.github.com>
AuthorDate: Fri Jul 28 22:42:10 2023 +0800
RATIS-1861. NullPointerException in readAsync when Ratis leader is changing (#895)
---
.../src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java | 3 ++-
.../src/main/java/org/apache/ratis/server/impl/RoleInfo.java | 5 ++---
2 files changed, 4 insertions(+), 4 deletions(-)
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 8f8c0a982..341890588 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
@@ -569,10 +569,11 @@ class RaftServerImpl implements RaftServer.Division,
Preconditions.assertTrue(getInfo().isCandidate());
role.shutdownLeaderElection();
setRole(RaftPeerRole.LEADER, "changeToLeader");
+ final LeaderStateImpl leader = role.updateLeaderState(this);
state.becomeLeader();
// start sending AppendEntries RPC to followers
- final LogEntryProto e = role.startLeaderState(this);
+ final LogEntryProto e = leader.start();
getState().setRaftConf(e);
}
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/RoleInfo.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/RoleInfo.java
index d09c8017b..603ba1326 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/RoleInfo.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/RoleInfo.java
@@ -18,7 +18,6 @@
package org.apache.ratis.server.impl;
-import org.apache.ratis.proto.RaftProtos.LogEntryProto;
import org.apache.ratis.proto.RaftProtos.RaftPeerRole;
import org.apache.ratis.protocol.RaftPeerId;
import org.apache.ratis.util.Preconditions;
@@ -79,8 +78,8 @@ class RoleInfo {
return Objects.requireNonNull(leaderState.get(), "leaderState is null");
}
- LogEntryProto startLeaderState(RaftServerImpl server) {
- return updateAndGet(leaderState, new LeaderStateImpl(server)).start();
+ LeaderStateImpl updateLeaderState(RaftServerImpl server) {
+ return updateAndGet(leaderState, new LeaderStateImpl(server));
}
void shutdownLeaderState(boolean allowNull) {