Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ee16b4

Browse files
committed
Add regression tests for SELECT FOR UPDATE/SHARE NOWAIT.
Thomas Munro
1 parentd153b80 commit9ee16b4

File tree

7 files changed

+223
-0
lines changed

7 files changed

+223
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Parsed test spec with 2 sessions
2+
3+
starting permutation: s1a s2a s2b s1b s2c
4+
step s1a: SELECT * FROM foo FOR SHARE NOWAIT;
5+
id data
6+
7+
1 x
8+
step s2a: SELECT * FROM foo FOR SHARE NOWAIT;
9+
id data
10+
11+
1 x
12+
step s2b: SELECT * FROM foo FOR UPDATE NOWAIT;
13+
ERROR: could not obtain lock on row in relation "foo"
14+
step s1b: COMMIT;
15+
step s2c: COMMIT;
16+
17+
starting permutation: s2a s1a s2b s1b s2c
18+
step s2a: SELECT * FROM foo FOR SHARE NOWAIT;
19+
id data
20+
21+
1 x
22+
step s1a: SELECT * FROM foo FOR SHARE NOWAIT;
23+
id data
24+
25+
1 x
26+
step s2b: SELECT * FROM foo FOR UPDATE NOWAIT;
27+
ERROR: could not obtain lock on row in relation "foo"
28+
step s1b: COMMIT;
29+
step s2c: COMMIT;
30+
31+
starting permutation: s2a s2b s1a s1b s2c
32+
step s2a: SELECT * FROM foo FOR SHARE NOWAIT;
33+
id data
34+
35+
1 x
36+
step s2b: SELECT * FROM foo FOR UPDATE NOWAIT;
37+
id data
38+
39+
1 x
40+
step s1a: SELECT * FROM foo FOR SHARE NOWAIT;
41+
ERROR: could not obtain lock on row in relation "foo"
42+
step s1b: COMMIT;
43+
step s2c: COMMIT;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Parsed test spec with 3 sessions
2+
3+
starting permutation: s1a s2a s3a s1b s2b s3b
4+
step s1a: SELECT * FROM foo FOR UPDATE;
5+
id data
6+
7+
1 x
8+
step s2a: SELECT * FROM foo FOR UPDATE; <waiting ...>
9+
step s3a: SELECT * FROM foo FOR UPDATE NOWAIT;
10+
ERROR: could not obtain lock on row in relation "foo"
11+
step s1b: COMMIT;
12+
step s2a: <... completed>
13+
id data
14+
15+
1 x
16+
step s2b: COMMIT;
17+
step s3b: COMMIT;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Parsed test spec with 2 sessions
2+
3+
starting permutation: s1a s1b s2a s2b
4+
step s1a: SELECT * FROM foo FOR UPDATE NOWAIT;
5+
id data
6+
7+
1 x
8+
step s1b: COMMIT;
9+
step s2a: SELECT * FROM foo FOR UPDATE NOWAIT;
10+
id data
11+
12+
1 x
13+
step s2b: COMMIT;
14+
15+
starting permutation: s1a s2a s1b s2b
16+
step s1a: SELECT * FROM foo FOR UPDATE NOWAIT;
17+
id data
18+
19+
1 x
20+
step s2a: SELECT * FROM foo FOR UPDATE NOWAIT;
21+
ERROR: could not obtain lock on row in relation "foo"
22+
step s1b: COMMIT;
23+
step s2b: COMMIT;
24+
25+
starting permutation: s1a s2a s2b s1b
26+
step s1a: SELECT * FROM foo FOR UPDATE NOWAIT;
27+
id data
28+
29+
1 x
30+
step s2a: SELECT * FROM foo FOR UPDATE NOWAIT;
31+
ERROR: could not obtain lock on row in relation "foo"
32+
step s2b: COMMIT;
33+
step s1b: COMMIT;
34+
35+
starting permutation: s2a s1a s1b s2b
36+
step s2a: SELECT * FROM foo FOR UPDATE NOWAIT;
37+
id data
38+
39+
1 x
40+
step s1a: SELECT * FROM foo FOR UPDATE NOWAIT;
41+
ERROR: could not obtain lock on row in relation "foo"
42+
step s1b: COMMIT;
43+
step s2b: COMMIT;
44+
45+
starting permutation: s2a s1a s2b s1b
46+
step s2a: SELECT * FROM foo FOR UPDATE NOWAIT;
47+
id data
48+
49+
1 x
50+
step s1a: SELECT * FROM foo FOR UPDATE NOWAIT;
51+
ERROR: could not obtain lock on row in relation "foo"
52+
step s2b: COMMIT;
53+
step s1b: COMMIT;
54+
55+
starting permutation: s2a s2b s1a s1b
56+
step s2a: SELECT * FROM foo FOR UPDATE NOWAIT;
57+
id data
58+
59+
1 x
60+
step s2b: COMMIT;
61+
step s1a: SELECT * FROM foo FOR UPDATE NOWAIT;
62+
id data
63+
64+
1 x
65+
step s1b: COMMIT;

‎src/test/isolation/isolation_schedule

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ test: propagate-lock-delete
2525
test: drop-index-concurrently-1
2626
test: alter-table-1
2727
test: timeouts
28+
test: nowait
29+
test: nowait-2
30+
test: nowait-3
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Test NOWAIT with multixact locks.
2+
3+
setup
4+
{
5+
CREATETABLEfoo(
6+
idintPRIMARYKEY,
7+
datatextNOTNULL
8+
);
9+
INSERTINTOfooVALUES(1,'x');
10+
}
11+
12+
teardown
13+
{
14+
DROPTABLEfoo;
15+
}
16+
17+
session"s1"
18+
setup{ BEGIN;}
19+
step"s1a"{SELECT *FROMfooFORSHARENOWAIT;}
20+
step "s1b"{COMMIT;}
21+
22+
session "s2"
23+
setup{ BEGIN;}
24+
step "s2a"{SELECT *FROMfooFORSHARENOWAIT;}
25+
step "s2b"{SELECT *FROMfooFORUPDATENOWAIT;}
26+
step "s2c"{COMMIT;}
27+
28+
# s1 and s2 both get SHARE lock, creating a multixact lock, then s2
29+
# tries to upgrade to UPDATE but aborts because it cannot acquire a
30+
# multi-xact lock
31+
permutation "s1a" "s2a" "s2b" "s1b" "s2c"
32+
# the same but with the SHARE locks acquired in a different order, so
33+
# s2 again aborts because it can't acquired a multi-xact lock
34+
permutation "s2a" "s1a" "s2b" "s1b" "s2c"
35+
# s2 acquires SHARE then UPDATE, then s1 tries to acquire SHARE but
36+
# can't so aborts because it can't acquire a regular lock
37+
permutation "s2a" "s2b" "s1a" "s1b" "s2c"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Test NOWAIT with tuple locks.
2+
3+
setup
4+
{
5+
CREATETABLEfoo (
6+
idintPRIMARYKEY,
7+
datatextNOTNULL
8+
);
9+
INSERTINTOfooVALUES (1,'x');
10+
}
11+
12+
teardown
13+
{
14+
DROPTABLEfoo;
15+
}
16+
17+
session"s1"
18+
setup{BEGIN; }
19+
step"s1a"{SELECT*FROMfooFORUPDATE; }
20+
step"s1b"{COMMIT; }
21+
22+
session"s2"
23+
setup{BEGIN; }
24+
step"s2a"{SELECT*FROMfooFORUPDATE; }
25+
step"s2b"{COMMIT; }
26+
27+
session"s3"
28+
setup{BEGIN; }
29+
step"s3a"{SELECT*FROMfooFORUPDATENOWAIT; }
30+
step"s3b"{COMMIT; }
31+
32+
# s3 skips to second record due to tuple lock held by s2
33+
permutation"s1a""s2a""s3a""s1b""s2b""s3b"

‎src/test/isolation/specs/nowait.spec

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Test NOWAIT when regular row locks can't be acquired.
2+
3+
setup
4+
{
5+
CREATETABLEfoo (
6+
idintPRIMARYKEY,
7+
datatextNOTNULL
8+
);
9+
INSERTINTOfooVALUES (1,'x');
10+
}
11+
12+
teardown
13+
{
14+
DROPTABLEfoo;
15+
}
16+
17+
session"s1"
18+
setup{BEGIN; }
19+
step"s1a"{SELECT*FROMfooFORUPDATENOWAIT; }
20+
step"s1b"{COMMIT; }
21+
22+
session"s2"
23+
setup{BEGIN; }
24+
step"s2a"{SELECT*FROMfooFORUPDATENOWAIT; }
25+
step"s2b"{COMMIT; }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp