Skip to content

Commit aa0ddf7

Browse files
committed
modify the checking rule for shouldInstallSnapshot()
1 parent f5e9935 commit aa0ddf7

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,10 @@ public interface FollowerInfo {
112112

113113
/** Update lastRpcResponseTime and LastRespondedAppendEntriesSendTime */
114114
void updateLastRespondedAppendEntriesSendTime(Timestamp sendTime);
115+
116+
/** Set the caughtUp flag to true. */
117+
void catchUp();
118+
119+
/** @return true if this follower is caught up. */
120+
boolean isCaughtUp();
115121
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ default SnapshotInfo shouldInstallSnapshot() {
147147
// 2. or the follower's next index is smaller than the log start index
148148
// 3. or the follower is bootstrapping and has not installed any snapshot yet
149149
final FollowerInfo follower = getFollower();
150-
final boolean isFollowerBootstrapping = getLeaderState().isFollowerBootstrapping(follower);
150+
final boolean isFollowerCaughtUp = follower.isCaughtUp();
151151
final SnapshotInfo snapshot = getServer().getStateMachine().getLatestSnapshot();
152152

153-
if (isFollowerBootstrapping && !follower.hasAttemptedToInstallSnapshot()) {
153+
if (!isFollowerCaughtUp && !follower.hasAttemptedToInstallSnapshot()) {
154154
if (snapshot == null) {
155155
// Leader cannot send null snapshot to follower. Hence, acknowledge InstallSnapshot attempt (even though it
156156
// was not attempted) so that follower can come out of staging state after appending log entries.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,13 @@ public String toString() {
173173
", lastRpcResponseTime=" + lastRpcResponseTime.get().elapsedTimeMs() + ")";
174174
}
175175

176-
void catchUp() {
176+
@Override
177+
public void catchUp() {
177178
caughtUp = true;
178179
}
179180

180-
boolean isCaughtUp() {
181+
@Override
182+
public boolean isCaughtUp() {
181183
return caughtUp;
182184
}
183185

0 commit comments

Comments
 (0)