Skip to content

raft: optimize the leader commit term check #137826

@pav-kv

Description

@pav-kv

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

Metadata

Metadata

Assignees

Labels

A-kv-replicationRelating to Raft, consensus, and coordination.C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)C-performancePerf of queries or internals. Solution not expected to change functional behavior.T-kvKV Team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions