|
| 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 | +# |
| 7 | +# [1] http://www.cs.umb.edu/~poneil/ROAnom.pdf |
| 8 | + |
| 9 | +setup |
| 10 | +{ |
| 11 | +CREATETABLEbank_account (idTEXTPRIMARYKEY,balanceDECIMALNOTNULL); |
| 12 | +INSERTINTObank_account (id,balance)VALUES ('X',0), ('Y',0); |
| 13 | +} |
| 14 | + |
| 15 | +teardown |
| 16 | +{ |
| 17 | +DROPTABLEbank_account; |
| 18 | +} |
| 19 | + |
| 20 | +session"s1" |
| 21 | +setup {BEGINTRANSACTIONISOLATIONLEVELSERIALIZABLE; } |
| 22 | +step"s1ry"{SELECTbalanceFROMbank_accountWHEREid='Y'; } |
| 23 | +step"s1wy"{UPDATEbank_accountSETbalance=20WHEREid='Y'; } |
| 24 | +step"s1c" {COMMIT; } |
| 25 | + |
| 26 | +session"s2" |
| 27 | +setup{BEGINTRANSACTIONISOLATIONLEVELSERIALIZABLE; } |
| 28 | +step"s2rx"{SELECTbalanceFROMbank_accountWHEREid='X'; } |
| 29 | +step"s2ry"{SELECTbalanceFROMbank_accountWHEREid='Y'; } |
| 30 | +step"s2wx"{UPDATEbank_accountSETbalance=-11WHEREid='X'; } |
| 31 | +step"s2c"{COMMIT; } |
| 32 | + |
| 33 | +session"s3" |
| 34 | +setup{BEGINTRANSACTIONISOLATIONLEVELSERIALIZABLE; } |
| 35 | +step"s3r"{SELECTid,balanceFROMbank_accountWHEREidIN ('X','Y')ORDERBYid; } |
| 36 | +step"s3c"{COMMIT; } |
| 37 | + |
| 38 | +# without s3, s1 and s2 commit |
| 39 | +permutation"s2rx""s2ry""s1ry""s1wy""s1c""s2wx""s2c""s3c" |
| 40 | + |
| 41 | +# once s3 observes the data committed by s1, a cycle is created and s2 aborts |
| 42 | +permutation"s2rx""s2ry""s1ry""s1wy""s1c""s3r""s3c""s2wx" |