tikv / raft-rs

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

Make request_snapshot more safer #499

Closed ethercflow closed 1 year ago

ethercflow commented 1 year ago

Change

Modify request_snapshot API, remove parameter: request_index: u64, use last_index as request_index, when sending request snapshot.

Reason

When a follower uses this interface to actively request a snapshot from the leader, it is not safe to pass an arbitrary index, as the leader will continue to send AppendRPC before receiving the snapshot request, this gap log follower is difficult to handle. Eg: it may panic at https://github.com/tikv/raft-rs/blob/5ce52b480065ff31ecef16b9b77c7c3b7c57c8c7/src/raw_node.rs#L520-L529. So the safest way is to use last_index as request_index, and the follower rejects appendRPC.

close tikv/raft-rs#498

Signed-off-by: Wenbo Zhang ethercflow@gmail.com

ethercflow commented 1 year ago

@Connor1996 @BusyJay PTAL, thanks!