Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
leader 上 _logs_in_memory 中缓存的 LogEntry 会在 apply 完成且写到盘上后被清理掉。
leader 在 append_entries rpc 中需要获取 prev_log_term。
如果请求的并发比较小,发送新Log时,前一个LogEntry 很有可能已经从缓存清理掉了,prev_log_term 只能从 LogStorage 获取。(场景: 一个server上,node 数量特别多,但是单个node qps 比较小,能观察到 bvar raft_read_term_from_storage_second 很高)
这个 pr 在 clear_memory_logs 时多保留 log,使得上面场景总能通过缓存查询到 prev_log_term。
如果长时间不写,最后这个保留的 log 会在打快照的时候被清理掉。