Skip to main content

Module group_commit

Module group_commit 

Source
Expand description

Group commit coordinator.

Batches concurrent WAL write requests into a single fsync for maximum NVMe IOPS.

§How it works

  1. Multiple threads submit PendingWrite to the commit queue.
  2. One thread becomes the “commit leader” (acquires the commit lock).
  3. The leader drains all pending writes, appends them to the WAL writer, issues a single fsync, and advances durable_lsn.
  4. Non-leader threads discover their write was already committed when the pending queue is empty after acquiring the commit lock. They verify the commit succeeded via last_commit_failed before returning durable: true.

This converts N fsyncs into 1 fsync, which is critical for NVMe performance.

§Safety invariants

  • durable_lsn is updated atomically only after a successful fsync.
  • If fsync fails, last_commit_failed is set so non-leader threads whose writes were in the failed batch propagate the error instead of falsely reporting durable: true.
  • Fsync failure is treated as fatal for the batch — the data may or may not be on disk, and the caller must handle the error (retry, abort, etc.).

Structs§

CommitResult
Result delivered to each waiter after group commit completes.
GroupCommitter
Thread-safe group commit coordinator.
PendingWrite
A pending write request waiting to be committed.