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

Commit0e73327

Browse files
committed
Add subxid-overflow "isolation" test
This test covers a few lines of subxid-overflow-handling code in variouspart 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 parent3fd1f4b commit0e73327

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

‎src/include/storage/proc.h

Lines changed: 2 additions & 0 deletions
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
#definePGPROC_MAX_CACHED_SUBXIDS 64/* XXX guessed-at value */
3739

Lines changed: 82 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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
Lines changed: 79 additions & 0 deletions
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+
DROPTABLEIFEXISTSsubxids;
9+
CREATETABLEsubxids(subxinteger,valinteger);
10+
11+
CREATEORREPLACEFUNCTIONgen_subxids(ninteger)
12+
RETURNSVOID
13+
LANGUAGEplpgsql
14+
AS $$
15+
BEGIN
16+
IFn <=0THEN
17+
UPDATEsubxidsSETval=1WHEREsubx=0;
18+
RETURN;
19+
ELSE
20+
PERFORMgen_subxids(n -1);
21+
RETURN;
22+
ENDIF;
23+
EXCEPTION /*generatesasubxid */
24+
WHENraise_exceptionTHENNULL;
25+
END;
26+
$$;
27+
}
28+
29+
teardown
30+
{
31+
DROPTABLEsubxids;
32+
DROPFUNCTIONgen_subxids(integer);
33+
}
34+
35+
sessions1
36+
# setup step for each test
37+
stepins{TRUNCATEsubxids;INSERTINTOsubxidsVALUES(0,0);}
38+
# long running transaction with overflowed subxids
39+
stepsubxov{ BEGIN;SELECTgen_subxids(100);}
40+
# commit should always come last to make this long running
41+
steps1c{COMMIT;}
42+
43+
sessions2
44+
# move xmax forwards
45+
stepxmax{ BEGIN;INSERTINTOsubxidsVALUES(99,0);COMMIT;}
46+
47+
# step for test1
48+
steps2sel{SELECTvalFROMsubxidsWHEREsubx=0;}
49+
50+
# steps for test2
51+
steps2brr{ BEGINISOLATIONLEVELREPEATABLEREAD;}
52+
steps2brc{ BEGINISOLATIONLEVELREADCOMMITTED;}
53+
# look for data written by sub3
54+
steps2s3{SELECTvalFROMsubxidsWHEREsubx=1;}
55+
steps2c{COMMIT;}
56+
57+
# step for test3
58+
steps2upd{UPDATEsubxidsSETval=1WHEREsubx=0;}
59+
60+
sessions3
61+
# transaction with subxids that can commit before s1c
62+
stepsub3{ BEGIN;SAVEPOINTs;INSERTINTOsubxidsVALUES(1,0);}
63+
steps3c{COMMIT;}
64+
65+
# test1
66+
# s2sel will see subxid as still running
67+
# designed to test XidInMVCCSnapshot() when overflows, xid is found
68+
permutationinssubxovxmaxs2sels1c
69+
70+
# test2
71+
# designed to test XidInMVCCSnapshot() when overflows, xid is not found
72+
# both SELECTs invisible
73+
permutationinssubxovsub3xmaxs2brrs2s3s3cs2s3s2cs1c
74+
# 2nd SELECT visible after commit
75+
permutationinssubxovsub3xmaxs2brcs2s3s3cs2s3s2cs1c
76+
77+
# test3
78+
# designed to test XactLockTableWait() for overflows
79+
permutationinssubxovxmaxs2upds1c

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp