Make sure to not go backwards on applied or commit indexes

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2021-01-26 14:07:52 -08:00
parent df0228f076
commit 3e8d295239

View File

@@ -559,6 +559,11 @@ func (n *raft) Applied(index uint64) {
n.Lock()
defer n.Unlock()
// Ignore if already applied.
if index <= n.applied {
return
}
// FIXME(dlc) - Check spec on error conditions, storage
n.applied = index
// FIXME(dlc) - Can be more efficient here.
@@ -1319,6 +1324,10 @@ func (n *raft) loadEntry(index uint64) (*appendEntry, error) {
// applyCommit will update our commit index and apply the entry to the apply chan.
// lock should be held.
func (n *raft) applyCommit(index uint64) {
if index <= n.commit {
n.debug("Ignoring apply commit for %d, already processed", index)
return
}
original := n.commit
n.commit = index