Skip to content

Commit 3247c7f

Browse files
authored
RATIS-2283. GrpcLogAppender Thread Restart Leaves catchup=false, Blocking Reconfiguration Progress (#1250)
1 parent 8ab57e1 commit 3247c7f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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
@@ -145,7 +145,7 @@ default SnapshotInfo shouldInstallSnapshot() {
145145
// we should install snapshot if the follower needs to catch up and:
146146
// 1. there is no local log entry but there is snapshot
147147
// 2. or the follower's next index is smaller than the log start index
148-
// 3. or the follower is bootstrapping and has not installed any snapshot yet
148+
// 3. or the follower is bootstrapping (i.e. not yet caught up) and has not installed any snapshot yet
149149
final FollowerInfo follower = getFollower();
150150
final boolean isFollowerBootstrapping = getLeaderState().isFollowerBootstrapping(follower);
151151
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
@@ -820,7 +820,9 @@ public void onFollowerSuccessAppendEntries(FollowerInfo follower) {
820820

821821
@Override
822822
public boolean isFollowerBootstrapping(FollowerInfo follower) {
823-
return isBootStrappingPeer(follower.getId());
823+
// It is better to check caught up than staging state
824+
// since a follower may have already caught up but still in the staging state.
825+
return !isCaughtUp(follower);
824826
}
825827

826828
private void checkStaging() {
@@ -852,7 +854,12 @@ private void checkStaging() {
852854
}
853855

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

858865
void submitUpdateCommitEvent() {

0 commit comments

Comments
 (0)