Repository navigation
RATIS-2737. Refactor the appendEntries code in RaftServerImpl - #1660
Merged
Merged
Conversation
szetszwo
reviewed
Oct 23, 2026
szetszwo
left a comment
Contributor
There was a problem hiding this comment.
@amaliujia , thanks for working on this!
The change looks good. Just have some minor comments inlined.
Comment on lines
+1459
to
+1461
| CommitInfoCache getCommitInfoCache() { | ||
| return commitInfoCache; | ||
| } |
Contributor
There was a problem hiding this comment.
Let's change it to updateCommitInfoCache(..). Then, we don't have to expose commitInfoCache.
void updateCommitInfoCache(List<CommitInfoProto> commitInfos) {
commitInfos.forEach(commitInfoCache::update);
}
Comment on lines
+1468
to
+1472
| void startFollowerStateIfStarting(Object reason) { | ||
| if (lifeCycle.compareAndTransition(State.STARTING, State.RUNNING)) { | ||
| role.startFollowerState(this, reason); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Let's pass isFollowerInitializing. It is easier to understand the if-condition when initializing ad compareAndTransition are together.
void startFollowerState(boolean isFollowerInitializing) {
if (!isFollowerInitializing && lifeCycle.compareAndTransition(State.STARTING, State.RUNNING)) {
// the follower has caught up (i.e. not initializing). If it is not already RUNNING, start it up.
role.startFollowerState(this, Op.APPEND_ENTRIES);
}
}
Comment on lines
+1463
to
+1465
| boolean isStartComplete() { | ||
| return startComplete.get(); | ||
| } |
Contributor
There was a problem hiding this comment.
Let's check it in the beginning of appendEntriesAsync(..). Then, we don't need this new method.
//RaftServerImpl
@Override
public CompletableFuture<AppendEntriesReplyProto> appendEntriesAsync(AppendEntriesRequestProto r)
throws IOException {
if (!startComplete.get()) {
throw new ServerNotReadyException(getMemberId() + ": The server role is not yet initialized.");
}
return appendEntriesHandler.appendEntriesAsync(r);
}
szetszwo
approved these changes
Oct 24, 2026
szetszwo
left a comment
Contributor
There was a problem hiding this comment.
+1 the change looks good.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Refactor the appendEntries code in RaftServerImpl and move the code to a self-contained class.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/RATIS-2737
How was this patch tested?
Existing tests