Skip to content

Conversation

@ivandika3
Copy link
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
Copy link
Contributor

@szetszwo szetszwo left a comment

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

Copy link
Contributor

@szetszwo szetszwo left a comment

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
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
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

Copy link
Contributor

@szetszwo szetszwo left a comment

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