-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e04488c
commit b7a736d
Showing
12 changed files
with
391 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# A dirty read is when c2 can read an uncommitted value set by c1. Snapshot | ||
# isolation prevents this. | ||
|
||
> CREATE TABLE test (id INT PRIMARY KEY, value STRING) | ||
--- | ||
ok | ||
|
||
c1:> BEGIN | ||
c1:> INSERT INTO test VALUES (1, 'a') | ||
--- | ||
ok | ||
|
||
c2:> BEGIN | ||
c2:> SELECT * FROM test WHERE id = 1 | ||
--- | ||
ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# A dirty write is when c2 overwrites an uncommitted value written by c1. | ||
# Snapshot isolation prevents this. | ||
|
||
> CREATE TABLE test (id INT PRIMARY KEY, value STRING) | ||
--- | ||
ok | ||
|
||
c1:> BEGIN | ||
c1:> INSERT INTO test VALUES (1, 'a') | ||
--- | ||
ok | ||
|
||
c2:> BEGIN | ||
c2:!> INSERT INTO test VALUES (1, 'a') | ||
--- | ||
c2: Error: serialization failure, retry transaction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# A fuzzy (or unrepeatable) read is when c2 sees a value change after c1 | ||
# updates it. Snapshot isolation prevents this. | ||
|
||
> CREATE TABLE test (id INT PRIMARY KEY, value STRING) | ||
> INSERT INTO test VALUES (1, 'a') | ||
--- | ||
ok | ||
|
||
c1:> BEGIN | ||
c2:> BEGIN | ||
--- | ||
ok | ||
|
||
c2:> SELECT * FROM test WHERE id = 1 | ||
--- | ||
c2: 1, 'a' | ||
|
||
c1:> UPDATE test SET value = 'b' WHERE id = 1 | ||
c1:> COMMIT | ||
c1:> SELECT * FROM test | ||
--- | ||
c1: 1, 'b' | ||
|
||
c2:> SELECT * FROM test WHERE id = 1 | ||
--- | ||
c2: 1, 'a' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# A lost update is when c1 and c2 both read a value and update it, where | ||
# c2's update replaces c1. Snapshot isolation prevents this. | ||
|
||
> CREATE TABLE test (id INT PRIMARY KEY, value STRING) | ||
--- | ||
ok | ||
|
||
|
||
c1:> BEGIN | ||
c1:> SELECT * FROM test WHERE id = 1 | ||
--- | ||
ok | ||
|
||
c2:> BEGIN | ||
c2:> SELECT * FROM test WHERE id = 1 | ||
--- | ||
ok | ||
|
||
c1:> INSERT INTO test VALUES (1, 'a') | ||
c1:> COMMIT | ||
--- | ||
ok | ||
|
||
c2:!> INSERT INTO test VALUES (1, 'a') | ||
--- | ||
c2: Error: serialization failure, retry transaction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# A phantom read is when t1 reads entries matching some predicate, but a | ||
# modification by t2 changes which entries match the predicate such that a later | ||
# read by t1 returns them. Snapshot isolation prevents this. | ||
|
||
> CREATE TABLE test (id INT PRIMARY KEY, value STRING) | ||
> INSERT INTO test VALUES (1, 'a'), (2, 'b'), (3, 'c') | ||
--- | ||
ok | ||
|
||
c1:> BEGIN | ||
c2:> BEGIN | ||
--- | ||
ok | ||
|
||
c1:> SELECT * FROM test WHERE id > 1 | ||
--- | ||
c1: 2, 'b' | ||
c1: 3, 'c' | ||
|
||
c2:> DELETE FROM test WHERE id = 2 | ||
c2:> INSERT INTO test VALUES (4, 'd') | ||
c2:> COMMIT | ||
--- | ||
ok | ||
|
||
c1:> SELECT * FROM test WHERE id > 1 | ||
--- | ||
c1: 2, 'b' | ||
c1: 3, 'c' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Read skew is when c1 reads a and b, but c2 modifies b in between the | ||
# reads. Snapshot isolation prevents this. | ||
|
||
> CREATE TABLE test (id INT PRIMARY KEY, value STRING) | ||
> INSERT INTO test VALUES (1, 'a'), (2, 'b') | ||
--- | ||
ok | ||
|
||
c1:> BEGIN | ||
c2:> BEGIN | ||
--- | ||
ok | ||
|
||
c1:> SELECT * FROM test WHERE id = 1 | ||
--- | ||
c1: 1, 'a' | ||
|
||
c2:> UPDATE test SET value = 'b' WHERE id = 1 | ||
c2:> UPDATE test SET value = 'a' WHERE id = 2 | ||
c2:> COMMIT | ||
--- | ||
ok | ||
|
||
c1:> SELECT * FROM test WHERE id = 2 | ||
--- | ||
c1: 2, 'b' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Write skew is when c1 reads a and writes it to b while c2 reads b and writes | ||
# it to a. Snapshot isolation does not prevent this, which is expected, so we | ||
# assert the anomalous behavior. Fixing this would require implementing | ||
# serializable snapshot isolation. | ||
|
||
> CREATE TABLE test (id INT PRIMARY KEY, value STRING) | ||
> INSERT INTO test VALUES (1, 'a'), (2, 'b') | ||
--- | ||
ok | ||
|
||
c1:> BEGIN | ||
c2:> BEGIN | ||
--- | ||
ok | ||
|
||
c1:> SELECT * FROM test WHERE id = 1 | ||
c2:> SELECT * FROM test WHERE id = 2 | ||
--- | ||
c1: 1, 'a' | ||
c2: 2, 'b' | ||
|
||
c1:> UPDATE test SET value = 'a' WHERE id = 2 | ||
c2:> UPDATE test SET value = 'b' WHERE id = 1 | ||
--- | ||
ok | ||
|
||
c1:> COMMIT | ||
c2:> COMMIT | ||
--- | ||
ok | ||
|
||
> SELECT * FROM test | ||
--- | ||
1, 'b' | ||
2, 'a' |
Oops, something went wrong.