-
Notifications
You must be signed in to change notification settings - Fork 118
Closed
Description
Describe the bug
According to the raft paper, commitIndex should increase monotonically. But under certain conditions pysyncobj violates it.
The root cause is that self.__raftCommitIndex is set to min(leaderCommitIndex, self.__getCurrentLogIndex()) unconditionally when processing msg append_entries.
PySyncObj/pysyncobj/syncobj.py
Line 921 in d9c2deb
| self.__raftCommitIndex = min(leaderCommitIndex, self.__getCurrentLogIndex()) |
To Reproduce
- Init a cluster with 3 nodes.
- Node 1 becomes Leader and send
append_entriesto other nodes. And its log is[{"cmd":"NO_OP","idx":1,"term":0},{"cmd":"NO_OP","idx":2,"term":1}] - Node 2 and Node 3 receive the
append_entries, and repliesnext_node_idx 2 - Node 1 receives the
next_node_idx 2. - Node 1 sends
append_entries - Node 2 and Node 3 receive the
append_entries, and repliesnext_node_idx 3 - Node 1 receives the
next_node_idx 3and updates its__raftMatchIndexof other nodes to2. - Node 1 advances
__raftCommitIndexto2. - Node 2 election times out, becomes leader, and sends
append_entrieswith__raftCommitIndex=1. - Node 1 receives the
append_entries, and sets__raftCommitIndex=1, which violates the monotonicity specification.
A Possible Fix
Add a condition check:
if leaderCommitIndex > self.__raftCommitIndex:
self.__raftCommitIndex = min(leaderCommitIndex, self.__getCurrentLogIndex())bakwc and alg-nju
Metadata
Metadata
Assignees
Labels
No labels