Skip to content

RATIS-2379. Support returning applied index for ReadIndex#1332

Merged
szetszwo merged 8 commits into
apache:masterfrom
ivandika3:read-index-applied-index
Jan 9, 2026
Merged

RATIS-2379. Support returning applied index for ReadIndex#1332
szetszwo merged 8 commits into
apache:masterfrom
ivandika3:read-index-applied-index

Conversation

@ivandika3

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Please refer to https://issues.apache.org/jira/browse/RATIS-2379

How was this patch tested?

Unit test.

@ivandika3 ivandika3 marked this pull request as ready for review January 7, 2026 01:20

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

@ivandika3 , Thanks for working on this!

Sorry that I reviewed this earlier but forgot to press "Submit review". Please see the comments inlined.

interface ReadIndex {
String PREFIX = Read.PREFIX + ".read-index";

String READ_INDEX_USE_APPLIED_INDEX_ENABLED_KEY = PREFIX + ".use.applied-index.enabled";

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 remove "use", i.e. raft.server.read-index.applied-index.enabled.
  • The field names must be the same as the String value. Otherwise, the TestConfUtils will fail as shown in the CI.
  • It needs a setter method.
    interface ReadIndex {
      String PREFIX = Read.PREFIX + ".read-index";

      String APPLIED_INDEX_ENABLED_KEY = PREFIX + ".applied-index.enabled";
      boolean APPLIED_INDEX_ENABLED_DEFAULT = false;
      static boolean appliedIndexEnabled(RaftProperties properties) {
        return getBoolean(properties::getBoolean, APPLIED_INDEX_ENABLED_KEY,
            APPLIED_INDEX_ENABLED_DEFAULT, getDefaultLog());
      }

      static void setAppliedIndexEnabled(RaftProperties properties, boolean enabled) {
        setBoolean(properties::setBoolean, APPLIED_INDEX_ENABLED_KEY, enabled);
      }
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

} else {
this.followerMaxGapThreshold = (long) (followerGapRatioMax * maxPendingRequests);
}
this.readIndexUseAppliedIndexEnabled = RaftServerConfigKeys.Read.ReadIndex

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.

Similarly, remove use.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

*/
CompletableFuture<Long> getReadIndex(Long readAfterWriteConsistentIndex) {
final long commitIndex = server.getRaftLog().getLastCommittedIndex();
final long lastAppliedOrCommitIndex = readIndexUseAppliedIndexEnabled ?

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 just call it index instead of lastAppliedOrCommitIndex.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated.


| **Property** | `raft.server.read.read-index.use.applied-index.enabled` |
|:----------------|:--------------------------------------------------------------------------|
| **Description** | whether leader return applied index instead of commit index for ReadIndex |

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.

Suggestion: "whether applied index (instead of commit index) is used for ReadIndex"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this is more concise. Updated.

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

@ivandika3 , thanks for the update! Just have a comment inlined about the names. Please take a look.

Comment on lines +272 to +281
String READ_INDEX_APPLIED_INDEX_ENABLED_KEY = PREFIX + ".applied-index.enabled";
boolean READ_INDEX_APPLIED_INDEX_ENABLED_DEFAULT = false;
static boolean readIndexAppliedIndexEnabled(RaftProperties properties) {
return getBoolean(properties::getBoolean, READ_INDEX_APPLIED_INDEX_ENABLED_KEY,
READ_INDEX_APPLIED_INDEX_ENABLED_DEFAULT, getDefaultLog());
}

static void setReadIndexAppliedIndexEnabled(RaftProperties properties, boolean enabled) {
setBoolean(properties::setBoolean, READ_INDEX_APPLIED_INDEX_ENABLED_KEY, enabled);
}

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 remove the "readIndex" prefix from the fields and methods since the interface name already has it, i.e.

 interface ReadIndex {
      String PREFIX = Read.PREFIX + ".read-index";

      String APPLIED_INDEX_ENABLED_KEY = PREFIX + ".applied-index.enabled";
      boolean APPLIED_INDEX_ENABLED_DEFAULT = false;
      static boolean appliedIndexEnabled(RaftProperties properties) {
        return getBoolean(properties::getBoolean, APPLIED_INDEX_ENABLED_KEY,
            APPLIED_INDEX_ENABLED_DEFAULT, getDefaultLog());
      }

      static void setAppliedIndexEnabled(RaftProperties properties, boolean enabled) {
        setBoolean(properties::setBoolean, APPLIED_INDEX_ENABLED_KEY, enabled);
      }
    }

(Since this is a public API, we have to be more meticulous.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

@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 51f1e8e into apache:master Jan 9, 2026
16 checks passed
@ivandika3

Copy link
Copy Markdown
Contributor Author

Thanks @szetszwo for the review.

@ivandika3 ivandika3 deleted the read-index-applied-index branch January 21, 2026 01:50
adoroszlai added a commit that referenced this pull request Mar 6, 2026
slfan1989 pushed a commit to slfan1989/ratis that referenced this pull request May 6, 2026
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