eBay / NuRaft

C++ implementation of Raft core logic as a replication library
Apache License 2.0
993 stars 235 forks source link

Add a new API to reset the whole state machine. #477

Closed JackyWoo closed 10 months ago

JackyWoo commented 10 months ago

Use case

If a node leave cluster for a long time, when it startup it wil first load local data into memory then it will receive the append_entry request from leader and leader will check data ga. If the gap can not satisfied by log, leader will send sanpshot.The newly startup node reveive the sanpshot and load it into memory.

But it should clear data in memory first, if not inconsistence may occur, details see here.

I think it is better to add a new reset API.

greensky00 commented 10 months ago

@JackyWoo Actually, apply_snapshot() is for the purpose of resetting state machine (and then applying snapshot). Why don't you put your clean-up logic into apply_snapshot()? Unless reset() is independently used for somewhere else in NuRaft, having that API separate from apply_snapshot() seems to me redundant.

JackyWoo commented 10 months ago

Got it, thanks.