| 1 |
# Daily Report of Receipts test. |
| 2 |
# |
| 3 |
# This test doesn't persist a bad state in the database; rather, it |
| 4 |
# provides a view of the data which is not consistent with any |
| 5 |
# order of execution of the serializable transactions. It |
| 6 |
# demonstrates a situation where the deposit date for receipts could |
| 7 |
# be changed and a report of the closed day's receipts subsequently |
| 8 |
# run which will miss a receipt from the date which has been closed. |
| 9 |
# |
| 10 |
# There are only six permutations which must cause a serialization failure. |
| 11 |
# Failure cases are where s1 overlaps both s2 and s3, but s2 commits before |
| 12 |
# s3 executes its first SELECT. |
| 13 |
# |
| 14 |
# As long as s3 is declared READ ONLY there should be no false positives. |
| 15 |
# If s3 were changed to READ WRITE, we would currently expect 42 false |
| 16 |
# positives. Further work dealing with de facto READ ONLY transactions |
| 17 |
# may be able to reduce or eliminate those false positives. |
| 18 |
|
| 19 |
setup |
| 20 |
{ |
| 21 |
CREATE TABLE ctl (k text NOT NULL PRIMARY KEY, deposit_date date NOT NULL); |
| 22 |
INSERT INTO ctl VALUES ('receipt', DATE '2008-12-22'); |
| 23 |
CREATE TABLE receipt (receipt_no int NOT NULL PRIMARY KEY, deposit_date date NOT NULL, amount numeric(13,2)); |
| 24 |
INSERT INTO receipt VALUES (1, (SELECT deposit_date FROM ctl WHERE k = 'receipt'), 1.00); |
| 25 |
INSERT INTO receipt VALUES (2, (SELECT deposit_date FROM ctl WHERE k = 'receipt'), 2.00); |
| 26 |
} |
| 27 |
|
| 28 |
teardown |
| 29 |
{ |
| 30 |
DROP TABLE ctl, receipt; |
| 31 |
} |
| 32 |
|
| 33 |
session s1 |
| 34 |
setup { BEGIN ISOLATION LEVEL SERIALIZABLE; } |
| 35 |
step rxwy1 { INSERT INTO receipt VALUES (3, (SELECT deposit_date FROM ctl WHERE k = 'receipt'), 4.00); } |
| 36 |
step c1 { COMMIT; } |
| 37 |
|
| 38 |
session s2 |
| 39 |
setup { BEGIN ISOLATION LEVEL SERIALIZABLE; } |
| 40 |
step wx2 { UPDATE ctl SET deposit_date = DATE '2008-12-23' WHERE k = 'receipt'; } |
| 41 |
step c2 { COMMIT; } |
| 42 |
|
| 43 |
session s3 |
| 44 |
setup { BEGIN ISOLATION LEVEL SERIALIZABLE, READ ONLY; } |
| 45 |
step rx3 { SELECT * FROM ctl WHERE k = 'receipt'; } |
| 46 |
step ry3 { SELECT * FROM receipt WHERE deposit_date = DATE '2008-12-22'; } |
| 47 |
step c3 { COMMIT; } |