Multi-Version Concurrency Control
Follow MVCC version selection and derive a write-skew anomaly that serializable snapshot isolation must prevent.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 3
- Reading time
- 2 min
In this article3 chapters
A snapshot specifies visibility
In multi-version concurrency control, an update produces a new version and a visibility rule determines which version a reader sees. In a simplified commit-timestamp model, a transaction at snapshot \(s\) reads the latest committed version with commit timestamp at most \(s\), plus its own writes. An actual engine can track the transactions active when the snapshot was taken. Reclamation must keep any older version still visible to a live snapshot. Long-running readers can therefore retain substantial history even if they rarely read.
Snapshot isolation defines the stable view a transaction may read. Version reclamation explains why cleaning up some older committed versions still has to wait for that view to expire.
Two legal writes can break a shared invariant
An on-call table must satisfy \(x+y\ge1\), where each variable is 1 if its doctor is on duty. Both transactions read \((x,y)=(1,1)\). Each concludes that the other doctor can cover and writes only its own row.
\[ T_1:\ r(y)=1,\ w(x,0),\qquad T_2:\ r(x)=1,\ w(y,0). \]
Snapshot isolation can commit both because the write sets are disjoint. The final state is \((0,0)\). Reading \(y=1\) requires \(T_1\) to precede \(T_2\) in any equivalent serial execution. The other read requires the reverse order. This cycle consists of two read–write anti-dependencies.
Serializable snapshot isolation tracks potential cycles
Serializable snapshot isolation can abort a transaction on detection of a “dangerous structure” consisting of two consecutive read–write anti-dependencies, with the necessary commit-order conditions. It monitors a sufficient condition for preventing cycles and can abort some histories that would have been serializable. Global distributed transactions introduce another requirement, the atomic decision across participants. Coordination for that decision and the isolation rules of the reads are separate parts of the specification. Real-time ordering imposes additional conditions as discussed in linearizability.[1][2]