Theoremadvanced
Dangerous structure theorem
Also called Fekete snapshot isolation theorem, consecutive rw-antidependencies theorem, dangerous structure.
Every cycle in the dependency graph of a snapshot isolation history has two rw-antidependency arcs in a row between concurrent transactions, and the last of the three commits first.
Statement
Let be a history of committed transactions under snapshot isolation: each has a start time and a commit time , all distinct, reads the last version of each item committed before (or its own write), and no two concurrent transactions write the same item (first-committer-wins). Two transactions are concurrent if and . Let be the dependency graph of committed transactions with ww, wr and rw arcs, with the versions of each item ordered by commit time.
Theorem (Fekete, Liarokapis, O'Neil, O'Neil and Shasha, 2005). Every cycle of contains two consecutive arcs such that and are concurrent, and are concurrent, and commits first among the transactions of the cycle. and may be the same transaction.
In plain words
Under snapshot isolation, a transaction that reads an item can miss a change that a concurrent transaction makes to it. That missed change is an "anti-dependency": the reader seems to come before the writer. A cycle of such orders means that no serial order exists. The theorem says that a bad cycle cannot be made of ordinary dependencies and a single missed change. It always needs two missed changes in a row, through a middle transaction (the pivot) that runs at the same time as both its neighbors. So a system can watch for a transaction that both misses a change and has its own change missed by another. Aborting such a transaction is enough to keep every result serializable.
Proof
All arcs join distinct committed transactions. Versions of an item are ordered by the commit times of their writers.
Lemma A. If or , then .
Proof. For ww, and both write the same item, so by first-committer-wins they are not concurrent. The version of follows that of , so . Not concurrent means or ; the second gives , which contradicts . For wr, reads the version of from its snapshot, which contains only versions committed before .
Lemma B. If , then .
Proof. reads a version from its snapshot, and installs the next version of after . If , the version of is in the snapshot of , and it is later than ; then reads it or a later one, not .
The theorem. Take a cycle, and let be the transaction in it with the smallest commit time. Let be the arc of the cycle that enters .
The arc into is rw. If it were ww or wr, Lemma A would give , against the choice of . So , and by Lemma B, . Also by the choice of , so , and with the two are concurrent.
The arc into is rw. Let be the arc of the cycle that enters ; is possible if the cycle has length 2. If the arc were ww or wr, Lemma A would give ; if this contradicts the choice of , and if it contradicts . So , and by Lemma B, . Also , since is the smallest commit time in the cycle. So and are concurrent.
A history whose DSG has no cycle is serializable, in the order of a topological sort, by the MVSG theorem. So every history under snapshot isolation that is not serializable contains the structure of the theorem.
Consequences
No cycle with a single anti-dependency. Every cycle has at least two rw arcs. So snapshot isolation forbids the phenomenon G-single of Adya's isolation levels, and with it the lost update, the non-repeatable read and read skew of the transaction anomalies. The anomalies it allows are those with two rw arcs: the write skew when the cycle has length 2, and longer cycles such as the read-only anomaly.
Read-only transactions. If in the theorem is read-only, then commits before starts. Proof. installs no versions, so no ww or rw arc enters it; the arc of the cycle that enters is , and Lemma A gives . Since , . In the read-only anomaly of Fekete, O'Neil and O'Neil (2004), the report starts after the deposit commits and misses the withdrawal , which is the pivot. A read-only transaction whose snapshot was taken before any such could commit is safe; PostgreSQL uses this rule for safe snapshots.
Run-time prevention. If the system aborts any transaction that has an rw arc in from a concurrent transaction and an rw arc out to a concurrent transaction, no committed history has the structure, so every committed history is serializable. This is serializable snapshot isolation (Cahill, Röhm and Fekete, 2008). The commit-order clause lets the system wait: a pivot is dangerous only if commits first.
Static analysis. For a fixed set of transaction programs, Fekete et al. build a static dependency graph with an arc between two programs when some executions of them conflict, and mark an rw arc vulnerable when the two can run concurrently without a ww conflict. If no program has a vulnerable arc in and a vulnerable arc out on a cycle, every execution under snapshot isolation is serializable. They showed in this way that TPC-C is serializable under snapshot isolation. This is one method for robustness against weak isolation. Fekete (PODS 2005) used the same graph to choose which programs must run under two-phase locking when the others run under snapshot isolation.
Removing a structure. A dangerous structure in the static graph is removed by adding a write that both programs on a vulnerable arc perform (materializing the conflict), or by turning the read of the arc into a write (promotion). Either way the arc gets a ww conflict and stops being vulnerable.
Tightness
The converse fails. A dangerous structure need not lie on a cycle. With , and , the history has between concurrent transactions with first to commit, yet it is serializable as . So the theorem gives a sufficient test for serializability, not a characterization, and methods built on it abort some serializable histories; the serializable snapshot isolation page discusses these false positives.
Two is the right number. A cycle can have exactly two rw arcs and no other arcs: the write skew has the cycle . So "two consecutive rw arcs" cannot be raised to three, and cannot be lowered to one by the first consequence.
Concurrency matters. An rw arc between transactions that are not concurrent is harmless: if , then is before in every order consistent with real time, and the arc agrees with that. A cycle can contain such arcs, but the theorem finds a pair of consecutive arcs where both are between concurrent transactions; a test that ignored concurrency would abort far more.
First-committer-wins is needed. Without it, two concurrent transactions may write the same item, Lemma A fails for ww arcs, and the lost update is a cycle with a single rw arc.
History
Berenson et al. defined snapshot isolation in 1995 and noted the write skew. Adya's thesis (1999) defined snapshot isolation by graph phenomena, which already exclude cycles with one anti-dependency. Fekete, O'Neil and O'Neil found the read-only anomaly in 2004. The theorem with two consecutive vulnerable edges was published by Fekete, Liarokapis, O'Neil, O'Neil and Shasha in ACM TODS in 2005, together with the static dependency graph and the TPC-C analysis; Fekete's PODS 2005 paper applied it to mixed isolation levels. Cahill, Röhm and Fekete built serializable snapshot isolation on it in 2008, and Ports and Grittner implemented it in PostgreSQL 9.1 in 2011, with the read-only rules above.
References
- Alan Fekete, Dimitrios Liarokapis, Elizabeth O'Neil, Patrick O'Neil and Dennis Shasha, Making snapshot isolation serializable, ACM Transactions on Database Systems 30(2), 2005, the theorem on two consecutive vulnerable anti-dependency edges in every cycle of an SI history, the static dependency graph, and the analysis of TPC-C; chapter level only
- Alan Fekete, Allocating isolation levels to transactions, Proceedings of ACM PODS 2005, pages 206 to 215, the use of the theorem to decide which programs must run with two-phase locking so that a mix of SI and locking is serializable, chapter level only
- Michael J. Cahill, Uwe Röhm and Alan Fekete, Serializable isolation for snapshot databases, Proceedings of ACM SIGMOD 2008, the run-time use of the theorem (abort a transaction with an rw arc in and an rw arc out) and the discussion of false positives, chapter level only
- Alan Fekete, Elizabeth O'Neil and Patrick O'Neil, A read-only transaction anomaly under snapshot isolation, ACM SIGMOD Record 33(3), 2004, pages 12 to 14, the three-transaction anomaly with a read-only transaction
- Hal Berenson, Phil Bernstein, Jim Gray, Jim Melton, Elizabeth O'Neil and Patrick O'Neil, A critique of ANSI SQL isolation levels, Proceedings of ACM SIGMOD 1995, Section 4.2, the definition of snapshot isolation with first-committer-wins
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W0 stub |
|
Tag Q5KMJR Edit this page History Report an error Markdown