Skip to content

M2.1: Batch WAL writes - #9

Merged
SantanuKar43 merged 2 commits into
mainfrom
m2.1/wal-batch-write
Apr 27, 2026
Merged

M2.1: Batch WAL writes#9
SantanuKar43 merged 2 commits into
mainfrom
m2.1/wal-batch-write

Conversation

@SantanuKar43

Copy link
Copy Markdown
Owner

In fsync ALWAYS mode, instead of writing to wal file and fsyncing on each command, batch multiple requests and fsync them together.

In ALWAYS mode, batching emerges naturally from Go’s synchronization: each request acquires w.mu, appends its entry to the shared asyncBuffer, updates UncommittedLSN, and releases the lock. So multiple goroutines quickly accumulate writes into the same buffer without blocking on disk I/O.

The first goroutine that notices no flush is in progress flips isFlushing and signals the flusher via flushChan. The flusher then acquires w.mu (mutually excluding new writers), drains the entire buffer in one go, updates CommittedLSN while holding the sync.Cond lock (CommitSignal.L), and finally calls Broadcast() to wake all waiting goroutines.

Each waiting request, which is blocked on the condition variable until its LSN ≤ CommittedLSN, proceeds only after the batch is durably written. So batching is achieved by many goroutines serializing appends via a mutex, but amortizing a single disk flush across all of them, coordinated through a condition variable for durability acknowledgment.

@SantanuKar43
SantanuKar43 merged commit 517e727 into main Apr 27, 2026
1 check passed
@SantanuKar43
SantanuKar43 deleted the m2.1/wal-batch-write branch April 27, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant