You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by "slfan1989 (via GitHub)" <gi...@apache.org> on 2026/10/03 04:29:51 UTC
[PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
slfan1989 opened a new pull request, #1625:
URL: https://github.com/apache/ratis/pull/1625
## What changes were proposed in this pull request?
Fix intermittent failures in the LogAppender purge tests caused by concurrent updates to the follower's `nextIndex`.
Previously, the tests modified the follower state of a running LogAppender.
Background replication could update `nextIndex` between preparing the request and checking the result, causing assertions to fail.
This patch uses an unstarted LogAppender with independent follower state for request construction and validation.
It also controls heartbeat timing so the tests consistently exercise data append requests.
The existing assertions are preserved.
## What is the link to the Apache JIRA
RATIS-2727. LogAppender purge tests may fail due to concurrent nextIndex updates.
## How was this patch tested?
https://github.com/slfan1989/ratis/actions/runs/36955632816
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
Posted by "slfan1989 (via GitHub)" <gi...@apache.org>.
slfan1989 commented on code in PR #1625:
URL: https://github.com/apache/ratis/pull/1625#discussion_r4175547920
##########
ratis-server/src/test/java/org/apache/ratis/LogAppenderTests.java:
##########
@@ -317,12 +317,14 @@ void runTestNewAppendEntriesRequestAfterPurge(RaftServer.Division leader,
final Stream<LogAppender> appenders = RaftServerTestUtil.getLogAppenders(leader);
Assertions.assertNotNull(appenders, "Leader should have log appenders");
- final LogAppender appender = appenders.findFirst().orElseThrow(
+ final LogAppender runningAppender = appenders.findFirst().orElseThrow(
() -> new AssertionError("No log appender found"));
Assertions.assertTrue(targetNextIndex > RaftLog.LEAST_VALID_LOG_INDEX,
"targetNextIndex should be > LEAST_VALID_LOG_INDEX");
- appender.getFollower().setNextIndex(targetNextIndex);
Review Comment:
This line modifies the follower state shared with the running appender.
After the test sets nextIndex, the background appender can advance it while processing a successful AppendEntries reply, before the test reaches the assertion below:
https://github.com/apache/ratis/blob/406422d197a13229adf8144102c111e270703238/ratis-server/src/main/java/org/apache/ratis/server/leader/LogAppenderDefault.java#L207-L211
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #1625:
URL: https://github.com/apache/ratis/pull/1625#discussion_r4174800223
##########
ratis-server/src/test/java/org/apache/ratis/LogAppenderTests.java:
##########
@@ -317,12 +317,14 @@ void runTestNewAppendEntriesRequestAfterPurge(RaftServer.Division leader,
final Stream<LogAppender> appenders = RaftServerTestUtil.getLogAppenders(leader);
Assertions.assertNotNull(appenders, "Leader should have log appenders");
- final LogAppender appender = appenders.findFirst().orElseThrow(
+ final LogAppender runningAppender = appenders.findFirst().orElseThrow(
() -> new AssertionError("No log appender found"));
Assertions.assertTrue(targetNextIndex > RaftLog.LEAST_VALID_LOG_INDEX,
"targetNextIndex should be > LEAST_VALID_LOG_INDEX");
- appender.getFollower().setNextIndex(targetNextIndex);
+ // Do not change the live appender's follower state: replication replies may update it concurrently.
+ final LogAppender appender = RaftServerTestUtil.newLogAppenderForTesting(
+ leader, runningAppender.getFollower().getPeer(), targetNextIndex);
Review Comment:
@slfan1989 , Question: When does it change the appender's follower state? All the code below are just Assertions?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
Posted by "slfan1989 (via GitHub)" <gi...@apache.org>.
slfan1989 commented on code in PR #1625:
URL: https://github.com/apache/ratis/pull/1625#discussion_r4180058580
##########
ratis-server/src/test/java/org/apache/ratis/LogAppenderTests.java:
##########
Review Comment:
Thanks @szetszwo! Updated as suggested. The `snapshotIndex` assertion now checks `runningAppender`, and the independent test appender is created after the precondition checks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo merged PR #1625:
URL: https://github.com/apache/ratis/pull/1625
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
Posted by "slfan1989 (via GitHub)" <gi...@apache.org>.
slfan1989 commented on PR #1625:
URL: https://github.com/apache/ratis/pull/1625#issuecomment-5993381133
> +1 the change looks good!
Thanks @ivandika3 and @szetszwo for the reviews, and @szetszwo for merging!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on PR #1625:
URL: https://github.com/apache/ratis/pull/1625#issuecomment-5973371539
Cc @ivandika3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
Posted by "slfan1989 (via GitHub)" <gi...@apache.org>.
slfan1989 commented on code in PR #1625:
URL: https://github.com/apache/ratis/pull/1625#discussion_r4175532352
##########
ratis-server/src/test/java/org/apache/ratis/LogAppenderTests.java:
##########
@@ -317,12 +317,14 @@ void runTestNewAppendEntriesRequestAfterPurge(RaftServer.Division leader,
final Stream<LogAppender> appenders = RaftServerTestUtil.getLogAppenders(leader);
Assertions.assertNotNull(appenders, "Leader should have log appenders");
- final LogAppender appender = appenders.findFirst().orElseThrow(
+ final LogAppender runningAppender = appenders.findFirst().orElseThrow(
() -> new AssertionError("No log appender found"));
Assertions.assertTrue(targetNextIndex > RaftLog.LEAST_VALID_LOG_INDEX,
"targetNextIndex should be > LEAST_VALID_LOG_INDEX");
- appender.getFollower().setNextIndex(targetNextIndex);
+ // Do not change the live appender's follower state: replication replies may update it concurrently.
+ final LogAppender appender = RaftServerTestUtil.newLogAppenderForTesting(
+ leader, runningAppender.getFollower().getPeer(), targetNextIndex);
Review Comment:
Thanks @szetszwo for reviewing this. You are right that the assertions themselves do not modify the follower state.
The concurrent update comes from the background replication thread.
The original code obtains a running appender from the leader and modifies its follower state:
```
appender.getFollower().setNextIndex(targetNextIndex);
```
This FollowerInfo is shared with the running appender. When a successful AppendEntries reply arrives, LogAppenderDefault.handleReply() may advance its nextIndex through getFollower().increaseNextIndex(nextIndex).
For example, the following interleaving is possible:
1. The test sets nextIndex to `58`.
2. The test calls `newAppendEntriesRequest()`, which returns null without changing nextIndex.
3. The background appender processes a successful replication reply and advances nextIndex to `61`.
4. The test asserts that nextIndex is still `58` and fails.
The assertion is intended to verify that `newAppendEntriesRequest()` leaves nextIndex unchanged when the previous log entry has been purged. With shared follower state, however, it can fail because of an unrelated background update.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RATIS-2727. Isolate follower state in LogAppender purge tests to avoid concurrent nextIndex updates. [ratis]
Posted by "szetszwo (via GitHub)" <gi...@apache.org>.
szetszwo commented on code in PR #1625:
URL: https://github.com/apache/ratis/pull/1625#discussion_r4178588051
##########
ratis-server/src/test/java/org/apache/ratis/LogAppenderTests.java:
##########
Review Comment:
We should use `runningAppender` here. Let's move down newLogAppenderForTesting(..):
```diff
+++ b/ratis-server/src/test/java/org/apache/ratis/LogAppenderTests.java
@@ -317,21 +317,23 @@ public abstract class LogAppenderTests<CLUSTER extends MiniRaftCluster>
final Stream<LogAppender> appenders = RaftServerTestUtil.getLogAppenders(leader);
Assertions.assertNotNull(appenders, "Leader should have log appenders");
- final LogAppender appender = appenders.findFirst().orElseThrow(
+ final LogAppender runningAppender = appenders.findFirst().orElseThrow(
() -> new AssertionError("No log appender found"));
Assertions.assertTrue(targetNextIndex > RaftLog.LEAST_VALID_LOG_INDEX,
"targetNextIndex should be > LEAST_VALID_LOG_INDEX");
- appender.getFollower().setNextIndex(targetNextIndex);
-
- LOG.info("Set follower nextIndex={}, startIndexAfterPurge={}, snapshotIndex={}",
- targetNextIndex, startIndexAfterPurge, appender.getFollower().getSnapshotIndex());
- Assertions.assertEquals(0, appender.getFollower().getSnapshotIndex(),
+ Assertions.assertEquals(0, runningAppender.getFollower().getSnapshotIndex(),
"Follower snapshotIndex should be 0 (default, never installed snapshot)");
Assertions.assertNull(leaderLog.getTermIndex(targetNextIndex - 1),
"Entry at previousIndex=" + (targetNextIndex - 1) + " should have been purged");
+ // Do not change the live appender's follower state: replication replies may update it concurrently.
+ final LogAppender appender = RaftServerTestUtil.newLogAppenderForTesting(
+ leader, runningAppender.getFollower().getPeer(), targetNextIndex);
+ LOG.info("Clone follower and set nextIndex={} with startIndexAfterPurge={}",
+ targetNextIndex, startIndexAfterPurge);
+
// Should return null instead of throwing NPE
Assertions.assertNull(appender.newAppendEntriesRequest(0, false),
"newAppendEntriesRequest should return null when previous TermIndex is not found");
```
##########
ratis-server/src/test/java/org/apache/ratis/LogAppenderTests.java:
##########
@@ -317,12 +317,14 @@ void runTestNewAppendEntriesRequestAfterPurge(RaftServer.Division leader,
final Stream<LogAppender> appenders = RaftServerTestUtil.getLogAppenders(leader);
Assertions.assertNotNull(appenders, "Leader should have log appenders");
- final LogAppender appender = appenders.findFirst().orElseThrow(
+ final LogAppender runningAppender = appenders.findFirst().orElseThrow(
() -> new AssertionError("No log appender found"));
Assertions.assertTrue(targetNextIndex > RaftLog.LEAST_VALID_LOG_INDEX,
"targetNextIndex should be > LEAST_VALID_LOG_INDEX");
- appender.getFollower().setNextIndex(targetNextIndex);
Review Comment:
I see. I missed this line previously.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@ratis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org