tikv / raft-rs

Raft distributed consensus algorithm implemented in Rust.
Apache License 2.0
2.97k stars 399 forks source link

Probe from index less than match #555

Open wego1236 opened 1 week ago

wego1236 commented 1 week ago

In probe mechanism there is chance for replication starting from an index less than match index in probe state, unlike that in replicate state. For example, a rejected probe response got delayed and is received when the leader falls into another probe state. This is a rare case of cause.

To my understanding, allowing such a smaller index implies we want to tolerate loss of already replicated log entries. raft-rs/src/tracker/progress.rs

        if request_snapshot == INVALID_INDEX {
            self.next_idx = cmp::min(rejected, match_hint + 1);
            if self.next_idx < 1 {
                self.next_idx = 1;
            }

In this code, there is chance to make Next < Match. But the invariant in raft is that Next > Match.

wego1236 commented 1 week ago

i also find in etcd it fix this bug in https://github.com/etcd-io/raft/pull/149

BusyJay commented 1 week ago

Good catch! Do you want to port the patch?

wego1236 commented 1 week ago

Yes,i'll do it right now!