Module 3 · Dive 3.2
The OCC commit.
Reads were free because the log never changes. Writes are the hard part: two writers can both want the next LSN. The local engine resolves it optimistically — each stages a commit against the head it read, and the append is a compare-and-swap on the head. One wins; the other is told {:conflict, head} and retries. Run it.
Two writers, one head
interactiveWhy optimistic, not locked
graft.design.mdA lock would make every writer wait even when there is no contention, which is most of the time. Optimistic concurrency assumes success and only pays on collision: stage freely, and let the single atomic swap on the head decide. The loser hasn’t corrupted anything — it simply re-reads the new head and tries again, which is cheap because reads are free. This is the local serialization, inside one process. The next dive is the same “one writer wins” idea one layer out, where the writers are different nodes and the referee is the object store.
References & sources
- Echo records
- graft.design.mdOCC commit, {:conflict, head} on the Volume
- store.design.mdstrict commit serialization
- External
- Optimistic concurrency controlstage, then compare-and-swap
- Compare-and-swapthe atomic head update
- Designing Data-Intensive Applications, Kleppmann 2017write conflicts, OCC (Ch. 7)