Skip to content

RATIS-2737. Refactor the appendEntries code in RaftServerImpl - #1660

Merged
szetszwo merged 2 commits into
apache:masterfrom
amaliujia:RATIS-2737
Oct 24, 2026
Merged

szetszwo merged 2 commits into
apache:masterfrom
amaliujia:RATIS-2737

Conversation

@amaliujia

Copy link
Copy Markdown
Contributor

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

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@szetszwo
szetszwo merged commit ce5553e into apache:master Oct 24, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants