Skip to content

Commit 21ce4e1

Browse files
RkGritszetszwo
authored andcommitted
RATIS-2283. GrpcLogAppender Thread Restart Leaves catchup=false, Blocking Reconfiguration Progress (apache#1250)
1 parent 39acebf commit 21ce4e1

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

ratis-server-api/src/main/java/org/apache/ratis/server/leader/LogAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ default SnapshotInfo shouldInstallSnapshot() {
143143
// we should install snapshot if the follower needs to catch up and:
144144
// 1. there is no local log entry but there is snapshot
145145
// 2. or the follower's next index is smaller than the log start index
146-
// 3. or the follower is bootstrapping and has not installed any snapshot yet
146+
// 3. or the follower is bootstrapping (i.e. not yet caught up) and has not installed any snapshot yet
147147
final FollowerInfo follower = getFollower();
148148
final boolean isFollowerBootstrapping = getLeaderState().isFollowerBootstrapping(follower);
149149
final SnapshotInfo snapshot = getServer().getStateMachine().getLatestSnapshot();

ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,9 @@ public void onFollowerSuccessAppendEntries(FollowerInfo follower) {
818818

819819
@Override
820820
public boolean isFollowerBootstrapping(FollowerInfo follower) {
821-
return isBootStrappingPeer(follower.getId());
821+
// It is better to check caught up than staging state
822+
// since a follower may have already caught up but still in the staging state.
823+
return !isCaughtUp(follower);
822824
}
823825

824826
private void checkStaging() {
@@ -850,7 +852,12 @@ private void checkStaging() {
850852
}
851853

852854
boolean isBootStrappingPeer(RaftPeerId peerId) {
853-
return Optional.ofNullable(stagingState).map(s -> s.contains(peerId)).orElse(false);
855+
final Optional<LogAppender> info = getLogAppender(peerId);
856+
if (info.isPresent()) {
857+
return !isCaughtUp(info.get().getFollower());
858+
}
859+
final ConfigurationStagingState staging = stagingState;
860+
return staging != null && staging.contains(peerId);
854861
}
855862

856863
void submitUpdateCommitEvent() {

0 commit comments

Comments
 (0)