baidu / braft

An industrial-grade C++ implementation of RAFT consensus algorithm based on brpc, widely used inside Baidu to build highly-available distributed systems.
Apache License 2.0
3.95k stars 881 forks source link

support set truncate_index manually in on_snapshot_save #457

Open JayiceZ opened 4 months ago

JayiceZ commented 4 months ago

In braft, creating a snapshot will result in the truncation of logs, and users can not decide which logs will be truncated after snapshot_save. But sometimes, user wants to take over it and decides which logs should be retained.

For example, last_index=20 now, And snapshot_save is issued, but I don’t want to truncate all the logs before 20. On the contrary, logs between 11-20 should be kept and only logs before 11 will be truncated. But now, users can't achieve it. : (

I believe it will be a useful feature. By fully controlling the truncate index, users can use raft log as WAL of non-volatile StateMachine or to implement CDC etc.