Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0e73327

Browse files
committed
Add subxid-overflow "isolation" test
This test covers a few lines of subxid-overflow-handling code in various part of the backend, which are otherwise uncovered. Author: Simon Riggs <simon.riggs@enterprisedb.com> Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com> Discussion: https://postgr.es/m/CANbhV-H8ov5+nCMBYQFKhO+UZJjrFgY_ORiMWr3RhS4+x44PzA@mail.gmail.com
1 parent 3fd1f4b commit 0e73327

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

src/include/storage/proc.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
* If none of the caches have overflowed, we can assume that an XID that's not
3333
* listed anywhere in the PGPROC array is not a running transaction. Else we
3434
* have to look at pg_subtrans.
35+
*
36+
* See src/test/isolation/specs/subxid-overflow.spec if you change this.
3537
*/
3638
#define PGPROC_MAX_CACHED_SUBXIDS 64 /* XXX guessed-at value */
3739

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Parsed test spec with 3 sessions
2+
3+
starting permutation: ins subxov xmax s2sel s1c
4+
step ins: TRUNCATE subxids; INSERT INTO subxids VALUES (0, 0);
5+
step subxov: BEGIN; SELECT gen_subxids(100);
6+
gen_subxids
7+
-----------
8+
9+
(1 row)
10+
11+
step xmax: BEGIN; INSERT INTO subxids VALUES (99, 0); COMMIT;
12+
step s2sel: SELECT val FROM subxids WHERE subx = 0;
13+
val
14+
---
15+
0
16+
(1 row)
17+
18+
step s1c: COMMIT;
19+
20+
starting permutation: ins subxov sub3 xmax s2brr s2s3 s3c s2s3 s2c s1c
21+
step ins: TRUNCATE subxids; INSERT INTO subxids VALUES (0, 0);
22+
step subxov: BEGIN; SELECT gen_subxids(100);
23+
gen_subxids
24+
-----------
25+
26+
(1 row)
27+
28+
step sub3: BEGIN; SAVEPOINT s; INSERT INTO subxids VALUES (1, 0);
29+
step xmax: BEGIN; INSERT INTO subxids VALUES (99, 0); COMMIT;
30+
step s2brr: BEGIN ISOLATION LEVEL REPEATABLE READ;
31+
step s2s3: SELECT val FROM subxids WHERE subx = 1;
32+
val
33+
---
34+
(0 rows)
35+
36+
step s3c: COMMIT;
37+
step s2s3: SELECT val FROM subxids WHERE subx = 1;
38+
val
39+
---
40+
(0 rows)
41+
42+
step s2c: COMMIT;
43+
step s1c: COMMIT;
44+
45+
starting permutation: ins subxov sub3 xmax s2brc s2s3 s3c s2s3 s2c s1c
46+
step ins: TRUNCATE subxids; INSERT INTO subxids VALUES (0, 0);
47+
step subxov: BEGIN; SELECT gen_subxids(100);
48+
gen_subxids
49+
-----------
50+
51+
(1 row)
52+
53+
step sub3: BEGIN; SAVEPOINT s; INSERT INTO subxids VALUES (1, 0);
54+
step xmax: BEGIN; INSERT INTO subxids VALUES (99, 0); COMMIT;
55+
step s2brc: BEGIN ISOLATION LEVEL READ COMMITTED;
56+
step s2s3: SELECT val FROM subxids WHERE subx = 1;
57+
val
58+
---
59+
(0 rows)
60+
61+
step s3c: COMMIT;
62+
step s2s3: SELECT val FROM subxids WHERE subx = 1;
63+
val
64+
---
65+
0
66+
(1 row)
67+
68+
step s2c: COMMIT;
69+
step s1c: COMMIT;
70+
71+
starting permutation: ins subxov xmax s2upd s1c
72+
step ins: TRUNCATE subxids; INSERT INTO subxids VALUES (0, 0);
73+
step subxov: BEGIN; SELECT gen_subxids(100);
74+
gen_subxids
75+
-----------
76+
77+
(1 row)
78+
79+
step xmax: BEGIN; INSERT INTO subxids VALUES (99, 0); COMMIT;
80+
step s2upd: UPDATE subxids SET val = 1 WHERE subx = 0; <waiting ...>
81+
step s1c: COMMIT;
82+
step s2upd: <... completed>

src/test/isolation/isolation_schedule

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test: fk-deadlock2
3434
test: fk-partitioned-1
3535
test: fk-partitioned-2
3636
test: fk-snapshot
37+
test: subxid-overflow
3738
test: eval-plan-qual
3839
test: eval-plan-qual-trigger
3940
test: lock-update-delete
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Subtransaction overflow
2+
#
3+
# This test is designed to cover some code paths which only occur when
4+
# one transaction has overflowed the subtransaction cache.
5+
6+
setup
7+
{
8+
DROP TABLE IF EXISTS subxids;
9+
CREATE TABLE subxids (subx integer, val integer);
10+
11+
CREATE OR REPLACE FUNCTION gen_subxids (n integer)
12+
RETURNS VOID
13+
LANGUAGE plpgsql
14+
AS $$
15+
BEGIN
16+
IF n <= 0 THEN
17+
UPDATE subxids SET val = 1 WHERE subx = 0;
18+
RETURN;
19+
ELSE
20+
PERFORM gen_subxids(n - 1);
21+
RETURN;
22+
END IF;
23+
EXCEPTION /* generates a subxid */
24+
WHEN raise_exception THEN NULL;
25+
END;
26+
$$;
27+
}
28+
29+
teardown
30+
{
31+
DROP TABLE subxids;
32+
DROP FUNCTION gen_subxids(integer);
33+
}
34+
35+
session s1
36+
# setup step for each test
37+
step ins { TRUNCATE subxids; INSERT INTO subxids VALUES (0, 0); }
38+
# long running transaction with overflowed subxids
39+
step subxov { BEGIN; SELECT gen_subxids(100); }
40+
# commit should always come last to make this long running
41+
step s1c { COMMIT; }
42+
43+
session s2
44+
# move xmax forwards
45+
step xmax { BEGIN; INSERT INTO subxids VALUES (99, 0); COMMIT;}
46+
47+
# step for test1
48+
step s2sel { SELECT val FROM subxids WHERE subx = 0; }
49+
50+
# steps for test2
51+
step s2brr { BEGIN ISOLATION LEVEL REPEATABLE READ; }
52+
step s2brc { BEGIN ISOLATION LEVEL READ COMMITTED; }
53+
# look for data written by sub3
54+
step s2s3 { SELECT val FROM subxids WHERE subx = 1; }
55+
step s2c { COMMIT; }
56+
57+
# step for test3
58+
step s2upd { UPDATE subxids SET val = 1 WHERE subx = 0; }
59+
60+
session s3
61+
# transaction with subxids that can commit before s1c
62+
step sub3 { BEGIN; SAVEPOINT s; INSERT INTO subxids VALUES (1, 0); }
63+
step s3c { COMMIT; }
64+
65+
# test1
66+
# s2sel will see subxid as still running
67+
# designed to test XidInMVCCSnapshot() when overflows, xid is found
68+
permutation ins subxov xmax s2sel s1c
69+
70+
# test2
71+
# designed to test XidInMVCCSnapshot() when overflows, xid is not found
72+
# both SELECTs invisible
73+
permutation ins subxov sub3 xmax s2brr s2s3 s3c s2s3 s2c s1c
74+
# 2nd SELECT visible after commit
75+
permutation ins subxov sub3 xmax s2brc s2s3 s3c s2s3 s2c s1c
76+
77+
# test3
78+
# designed to test XactLockTableWait() for overflows
79+
permutation ins subxov xmax s2upd s1c

0 commit comments

Comments
 (0)