duongkame commented on PR #1011:
URL: https://github.com/apache/ratis/pull/1011#issuecomment-1894374538

   @szetszwo  Regarding `TestRaftWithSimulatedRpc`. What happened is:
   1. `s2` was the leader of term `2`.
   2. `s2` received a client request, added to log as `(t:2, i:1475)`.
   3. `s0` received `appendEntries` from `s2` for `(t:2, i:1475)`. A 
`TransactionContext` is 
[created](https://github.com/apache/ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLog.java#L477)
 for `(t:2, i:1475)` during `appendEntries` (I think this is wrong). 
   4. `1475` hadn't been replcated to majority of nodes,  `s0` hadn't applied 
it yet.
   5. Leader changed to `s1`. (`s1` hadn't received `appendEntries` for `(t:2, 
i:1475)`).
   6. `s1` received a client request, appended it as `1475`
   7. `s1` decreased `s0`'s `nextIndex`: `s1@group-9EAE5FF30820->s0: 
decreaseNextIndex nextIndex: updateUnconditionally 1475 -> 1474`
   8. `s0` received `appendEntries` from `s2` for `(t:2, i:1475)`, it looked up 
`TransactionContext` and saw one created per 3. Assertion 
`Preconditions.assertSame(getLogEntry().getTerm(), entry.getTerm(), 
"entry.term");` fails.
   
   I believe the problem is from the fact that TransactionContext is 
[created](https://github.com/apache/ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLog.java#L477)
 during `appendEntries`.
   
   ``` 
       // in SegmentedRaftLog#appendImpl
        for (int i = index; i < entries.size(); i++) {
           final LogEntryProto entry = entries.get(i);
           futures.add(appendEntry(entry, server.getTransactionContext(entry, 
true)));
         }
   ```
   `appendEntries` should lookup `TransactionContext` only, 
`TransactionContext` should be created once the entry is applied.
   ``` 
           futures.add(appendEntry(entry, server.getTransactionContext(entry, 
false)));
   ```
   
   Look at the failing test per 
https://github.com/apache/ratis/actions/runs/7516329635/artifacts/1167720078, 
`org.apache.ratis.server.simulation.TestRaftWithSimulatedRpc-output.txt`.
   
   
   


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