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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to