Debian Codegraph @

src/test/isolation/specs/serializable-parallel.spec

raw
1 # The example from the paper "A read-only transaction anomaly under snapshot
2 # isolation"[1].
3 #
4 # Here we test that serializable snapshot isolation (SERIALIZABLE) doesn't
5 # suffer from the anomaly, because s2 is aborted upon detection of a cycle.
6 # In this case the read only query s3 happens to be running in a parallel
7 # worker.
8 #
9 # [1] http://www.cs.umb.edu/~poneil/ROAnom.pdf
10
11 setup
12 {
13 CREATE TABLE bank_account (id TEXT PRIMARY KEY, balance DECIMAL NOT NULL);
14 INSERT INTO bank_account (id, balance) VALUES ('X', 0), ('Y', 0);
15 }
16
17 teardown
18 {
19 DROP TABLE bank_account;
20 }
21
22 session s1
23 setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
24 step s1ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
25 step s1wy { UPDATE bank_account SET balance = 20 WHERE id = 'Y'; }
26 step s1c { COMMIT; }
27
28 session s2
29 setup { BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; }
30 step s2rx { SELECT balance FROM bank_account WHERE id = 'X'; }
31 step s2ry { SELECT balance FROM bank_account WHERE id = 'Y'; }
32 step s2wx { UPDATE bank_account SET balance = -11 WHERE id = 'X'; }
33 step s2c { COMMIT; }
34
35 session s3
36 setup {
37 BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
38 SET debug_parallel_query = on;
39 }
40 step s3r { SELECT id, balance FROM bank_account WHERE id IN ('X', 'Y') ORDER BY id; }
41 step s3c { COMMIT; }
42
43 # without s3, s1 and s2 commit
44 permutation s2rx s2ry s1ry s1wy s1c s2wx s2c s3c
45
46 # once s3 observes the data committed by s1, a cycle is created and s2 aborts
47 permutation s2rx s2ry s1ry s1wy s1c s3r s3c s2wx