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

Erase last_segment from _segment when it transform into open_segment #293

Closed ehds closed 3 years ago

ehds commented 3 years ago

After truncating suffix log, a last_segment that exists in _segments maybe change from closed to open, so it would erase from _segments. Or it will be deleted twice when SegmentLogStorage::reset call.

https://github.com/baidu/braft/blob/154d805bd1eb88df97121fe1c73a5b469df88056/test/test_log.cpp#L374

In multi_segment_and_segment_logstorage unit test, after truncating suffix log at first_seg->last_index() + 1, last_segment at the second to last of the _segments which is closed, when it transform into open, it would erase from _segments. https://github.com/baidu/braft/blob/154d805bd1eb88df97121fe1c73a5b469df88056/src/braft/log.cpp#L927

ehds commented 3 years ago

@PFZheng PTAL.