Skip to content

Commit

Permalink
RATIS-1861. NullPointerException in readAsync when Ratis leader is ch…
Browse files Browse the repository at this point in the history
…anging (#895)
  • Loading branch information
HxpSerein authored Jul 28, 2023
1 parent 5c47d3b commit 45772bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,11 @@ synchronized void changeToLeader() {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,8 +78,8 @@ LeaderStateImpl getLeaderStateNonNull() {
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) {
Expand Down

0 comments on commit 45772bb

Please sign in to comment.