Skip to content

RATIS-2399. Avoid locks for commitIndex and snapshotIndex in RaftLogBase - #1612

Merged
szetszwo merged 4 commits into
apache:masterfrom
Elia-Renzoni:refactor/avoid-single-lock
Nov 18, 2026
Merged

szetszwo merged 4 commits into
apache:masterfrom
Elia-Renzoni:refactor/avoid-single-lock

Conversation

@Elia-Renzoni

@Elia-Renzoni Elia-Renzoni commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Avoid using write locks for both commitIndex and snapshotIndex

What is the link to the Apache JIRA

Jira Issue link:
https://issues.apache.org/jira/browse/RATIS-2399?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel

How was this patch tested?

This patch was tested via unit test

@Elia-Renzoni
Elia-Renzoni requested a review from szetszwo October 6, 2026 12:35
@Elia-Renzoni
Elia-Renzoni force-pushed the refactor/avoid-single-lock branch from 55057ec to 8a0adba Compare November 17, 2026 12:41
@Elia-Renzoni Elia-Renzoni changed the title RATIS-2399. Introduce separate locks for commitIndex and snapshotIndex in RaftLogBase RATIS-2399. Avoid locks for commitIndex and snapshotIndex in RaftLogBase Nov 17, 2026
@Elia-Renzoni

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I’ve addressed the suggested changes, and everything seems to work.

@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.

@Elia-Renzoni , thanks for the update! The change looks good.

See the minor comments below from Claude:

  1. Order in updateSnapshotIndex: update commitIndex before snapshotIndex. Without the lock, a reader can briefly see snapshotIndex > commitIndex with the current order. Updating commit first keeps commit >= snapshot true for every reader.
  2. Dead code: tryWriteLock(TimeDuration) (RaftLogBase.java:362) has no callers now. Remove it, or keep it if external subclasses might use it. It's public, but it isn't declared in the RaftLog interface.
  3. Trace log text changes from "updateIncreasingly" to "updateToMax old=.., new=.., updated? true". That's fine, but the "updated? " part is redundant because the message only prints when updated is true (RaftLogIndex.java:79). This is optional cleanup in ratis-server-api.

Signed-off-by: Elia Renzoni <elia.renzoni03@gmail.com>
@Elia-Renzoni

Copy link
Copy Markdown
Contributor Author

@Elia-Renzoni , thanks for the update! The change looks good.

See the minor comments below from Claude:

  1. Order in updateSnapshotIndex: update commitIndex before snapshotIndex. Without the lock, a reader can briefly see snapshotIndex > commitIndex with the current order. Updating commit first keeps commit >= snapshot true for every reader.
  2. Dead code: tryWriteLock(TimeDuration) (RaftLogBase.java:362) has no callers now. Remove it, or keep it if external subclasses might use it. It's public, but it isn't declared in the RaftLog interface.
  3. Trace log text changes from "updateIncreasingly" to "updateToMax old=.., new=.., updated? true". That's fine, but the "updated? " part is redundant because the message only prints when updated is true (RaftLogIndex.java:79). This is optional cleanup in ratis-server-api.

I've addressed the suggested cleanups here: 5aac204

@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 39d6596 into apache:master Nov 18, 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