-
Notifications
You must be signed in to change notification settings - Fork 4.1k
raft: optimize the leader commit term check #137826
Description
In raft, entries are committed when a current-term entry is persisted on a quorum of replicas. This requires checking the term of an entry at a particular index in the log.
Best-case, the entry at this index is still in memory (either in the raft's unstable structure, or in the raft log entries cache), so the term check is cheap. Worst-case, the entries have been rotated out of memory, and this check requires loading the entry from storage.
Since this check is on the critical path for writes in CRDB, we would like to eliminate the worst case. The leader can remember the log index at which it started appending entries from its term. Entries at >= this index all have the leader's term. This allows doing the commit term check in memory, without needing to load entries from the log.
The solution can be further generalized to #136296.
Jira issue: CRDB-45763