Closed meteam2022 closed 10 months ago
Thanks for pointing it out. I feel the main reason is we don't know the sent AppendEntriesRpc message, so we have to hold it somewhere when we receive the result from followers. The entries sent should be a readonly view, not the original entries object. Or we need to consider some way to prevent reading the same entries object from 2 threads. I think your proposal should work. Would you mind creating a pull request for it?
When the network latency is high, a
kvstore-set
operation may be inserted between sending theAppendEntriesRpc
msg and receiving theAppendEntriesResultMessage
. The entries in theAppendEntriesRpc
is a view of entrySequence. Upon receiving theAppendEntriesResultMessage
, the entries in AppendEntriesRpc has been concurrently modified, triggeringjava.util.ConcurrentModificationException
.The
kvstore-set
operation results in appending a log entry to the entrySequence:https://github.com/xnnyygn/xraft/blob/3fab4b12bb2ff86939011127feeaa86e688de7a9/xraft-core/src/main/java/in/xnnyygn/xraft/core/log/AbstractLog.java#L144-L148
Processing
AppendEntriesResultMessage
involves reading the entries that have been concurrently changed:https://github.com/xnnyygn/xraft/blob/c63dd0011497faa576057119b4455fe9e401dcef/xraft-core/src/main/java/in/xnnyygn/xraft/core/rpc/message/AppendEntriesRpc.java#L76-L78
Log (note that the timestamps are fake):
A possible fix
Create a copy of the subList into a new List: