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

Commit 0844b39

Browse files
committed
Improve test coverage for changes to inplace-updated catalogs.
This covers both regular and inplace changes, since bugs arise at their intersection. Where marked, these witness extant bugs. Back-patch to v12 (all supported versions). Reviewed (in an earlier version) by Robert Haas. Discussion: https://postgr.es/m/20240512232923.aa.nmisch@google.com
1 parent 22a4b10 commit 0844b39

16 files changed

+708
-1
lines changed

src/bin/pgbench/t/001_pgbench_with_server.pl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ sub check_data_state
6868
"CREATE TYPE pg_temp.e AS ENUM ($labels); DROP TYPE pg_temp.e;"
6969
});
7070

71+
# Test inplace updates from VACUUM concurrent with heap_update from GRANT.
72+
# The PROC_IN_VACUUM environment can't finish MVCC table scans consistently,
73+
# so this fails rarely. To reproduce consistently, add a sleep after
74+
# GetCatalogSnapshot(non-catalog-rel).
75+
Test::More->builder->todo_start('PROC_IN_VACUUM scan breakage');
76+
$node->safe_psql('postgres', 'CREATE TABLE ddl_target ()');
77+
$node->pgbench(
78+
'--no-vacuum --client=5 --protocol=prepared --transactions=50',
79+
0,
80+
[qr{processed: 250/250}],
81+
[qr{^$}],
82+
'concurrent GRANT/VACUUM',
83+
{
84+
'001_pgbench_grant@9' => q(
85+
DO $$
86+
BEGIN
87+
PERFORM pg_advisory_xact_lock(42);
88+
FOR i IN 1 .. 10 LOOP
89+
GRANT SELECT ON ddl_target TO PUBLIC;
90+
REVOKE SELECT ON ddl_target FROM PUBLIC;
91+
END LOOP;
92+
END
93+
$$;
94+
),
95+
'001_pgbench_vacuum_ddl_target@1' => "VACUUM ddl_target;",
96+
});
97+
Test::More->builder->todo_end;
98+
7199
# Trigger various connection errors
72100
$node->pgbench(
73101
'no-such-database',

src/test/isolation/expected/eval-plan-qual.out

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,3 +1337,29 @@ a|b|c| d
13371337
2|2|2|1004
13381338
(2 rows)
13391339

1340+
1341+
starting permutation: sys1 sysupd2 c1 c2
1342+
step sys1:
1343+
UPDATE pg_class SET reltuples = 123 WHERE oid = 'accounts'::regclass;
1344+
1345+
step sysupd2:
1346+
UPDATE pg_class SET reltuples = reltuples * 2
1347+
WHERE oid = 'accounts'::regclass;
1348+
<waiting ...>
1349+
step c1: COMMIT;
1350+
step sysupd2: <... completed>
1351+
step c2: COMMIT;
1352+
1353+
starting permutation: sys1 sysmerge2 c1 c2
1354+
step sys1:
1355+
UPDATE pg_class SET reltuples = 123 WHERE oid = 'accounts'::regclass;
1356+
1357+
step sysmerge2:
1358+
MERGE INTO pg_class
1359+
USING (SELECT 'accounts'::regclass AS o) j
1360+
ON o = oid
1361+
WHEN MATCHED THEN UPDATE SET reltuples = reltuples * 2;
1362+
<waiting ...>
1363+
step c1: COMMIT;
1364+
step sysmerge2: <... completed>
1365+
step c2: COMMIT;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Parsed test spec with 3 sessions
2+
3+
starting permutation: cachefill3 cir1 cic2 ddl3 read1
4+
step cachefill3: TABLE newly_indexed;
5+
c
6+
-
7+
(0 rows)
8+
9+
step cir1: BEGIN; CREATE INDEX i1 ON newly_indexed (c); ROLLBACK;
10+
step cic2: CREATE INDEX i2 ON newly_indexed (c);
11+
step ddl3: ALTER TABLE newly_indexed ADD extra int;
12+
step read1:
13+
SELECT relhasindex FROM pg_class WHERE oid = 'newly_indexed'::regclass;
14+
15+
relhasindex
16+
-----------
17+
f
18+
(1 row)
19+
20+
21+
starting permutation: cir1 cic2 ddl3 read1
22+
step cir1: BEGIN; CREATE INDEX i1 ON newly_indexed (c); ROLLBACK;
23+
step cic2: CREATE INDEX i2 ON newly_indexed (c);
24+
step ddl3: ALTER TABLE newly_indexed ADD extra int;
25+
step read1:
26+
SELECT relhasindex FROM pg_class WHERE oid = 'newly_indexed'::regclass;
27+
28+
relhasindex
29+
-----------
30+
t
31+
(1 row)
32+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Parsed test spec with 3 sessions
2+
3+
starting permutation: snap3 b1 grant1 vac2 snap3 c1 cmp3
4+
step snap3:
5+
INSERT INTO frozen_witness
6+
SELECT datfrozenxid FROM pg_database WHERE datname = current_catalog;
7+
8+
step b1: BEGIN;
9+
step grant1:
10+
GRANT TEMP ON DATABASE isolation_regression TO regress_temp_grantee;
11+
12+
step vac2: VACUUM (FREEZE);
13+
step snap3:
14+
INSERT INTO frozen_witness
15+
SELECT datfrozenxid FROM pg_database WHERE datname = current_catalog;
16+
17+
step c1: COMMIT;
18+
step cmp3:
19+
SELECT 'datfrozenxid retreated'
20+
FROM pg_database
21+
WHERE datname = current_catalog
22+
AND age(datfrozenxid) > (SELECT min(age(x)) FROM frozen_witness);
23+
24+
?column?
25+
----------------------
26+
datfrozenxid retreated
27+
(1 row)
28+
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
Parsed test spec with 5 sessions
2+
3+
starting permutation: b1 grant1 read2 addk2 c1 read2
4+
step b1: BEGIN;
5+
step grant1:
6+
GRANT SELECT ON intra_grant_inplace TO PUBLIC;
7+
8+
step read2:
9+
SELECT relhasindex FROM pg_class
10+
WHERE oid = 'intra_grant_inplace'::regclass;
11+
12+
relhasindex
13+
-----------
14+
f
15+
(1 row)
16+
17+
step addk2: ALTER TABLE intra_grant_inplace ADD PRIMARY KEY (c);
18+
step c1: COMMIT;
19+
step read2:
20+
SELECT relhasindex FROM pg_class
21+
WHERE oid = 'intra_grant_inplace'::regclass;
22+
23+
relhasindex
24+
-----------
25+
f
26+
(1 row)
27+
28+
29+
starting permutation: keyshr5 addk2
30+
step keyshr5:
31+
SELECT relhasindex FROM pg_class
32+
WHERE oid = 'intra_grant_inplace'::regclass FOR KEY SHARE;
33+
34+
relhasindex
35+
-----------
36+
f
37+
(1 row)
38+
39+
step addk2: ALTER TABLE intra_grant_inplace ADD PRIMARY KEY (c);
40+
41+
starting permutation: keyshr5 b3 sfnku3 addk2 r3
42+
step keyshr5:
43+
SELECT relhasindex FROM pg_class
44+
WHERE oid = 'intra_grant_inplace'::regclass FOR KEY SHARE;
45+
46+
relhasindex
47+
-----------
48+
f
49+
(1 row)
50+
51+
step b3: BEGIN ISOLATION LEVEL READ COMMITTED;
52+
step sfnku3:
53+
SELECT relhasindex FROM pg_class
54+
WHERE oid = 'intra_grant_inplace'::regclass FOR NO KEY UPDATE;
55+
56+
relhasindex
57+
-----------
58+
f
59+
(1 row)
60+
61+
step addk2: ALTER TABLE intra_grant_inplace ADD PRIMARY KEY (c);
62+
step r3: ROLLBACK;
63+
64+
starting permutation: b2 sfnku2 addk2 c2
65+
step b2: BEGIN;
66+
step sfnku2:
67+
SELECT relhasindex FROM pg_class
68+
WHERE oid = 'intra_grant_inplace'::regclass FOR NO KEY UPDATE;
69+
70+
relhasindex
71+
-----------
72+
f
73+
(1 row)
74+
75+
step addk2: ALTER TABLE intra_grant_inplace ADD PRIMARY KEY (c);
76+
step c2: COMMIT;
77+
78+
starting permutation: keyshr5 b2 sfnku2 addk2 c2
79+
step keyshr5:
80+
SELECT relhasindex FROM pg_class
81+
WHERE oid = 'intra_grant_inplace'::regclass FOR KEY SHARE;
82+
83+
relhasindex
84+
-----------
85+
f
86+
(1 row)
87+
88+
step b2: BEGIN;
89+
step sfnku2:
90+
SELECT relhasindex FROM pg_class
91+
WHERE oid = 'intra_grant_inplace'::regclass FOR NO KEY UPDATE;
92+
93+
relhasindex
94+
-----------
95+
f
96+
(1 row)
97+
98+
step addk2: ALTER TABLE intra_grant_inplace ADD PRIMARY KEY (c);
99+
step c2: COMMIT;
100+
101+
starting permutation: b3 sfu3 b1 grant1 read2 addk2 r3 c1 read2
102+
step b3: BEGIN ISOLATION LEVEL READ COMMITTED;
103+
step sfu3:
104+
SELECT relhasindex FROM pg_class
105+
WHERE oid = 'intra_grant_inplace'::regclass FOR UPDATE;
106+
107+
relhasindex
108+
-----------
109+
f
110+
(1 row)
111+
112+
step b1: BEGIN;
113+
step grant1:
114+
GRANT SELECT ON intra_grant_inplace TO PUBLIC;
115+
<waiting ...>
116+
step read2:
117+
SELECT relhasindex FROM pg_class
118+
WHERE oid = 'intra_grant_inplace'::regclass;
119+
120+
relhasindex
121+
-----------
122+
f
123+
(1 row)
124+
125+
step addk2: ALTER TABLE intra_grant_inplace ADD PRIMARY KEY (c);
126+
step r3: ROLLBACK;
127+
step grant1: <... completed>
128+
step c1: COMMIT;
129+
step read2:
130+
SELECT relhasindex FROM pg_class
131+
WHERE oid = 'intra_grant_inplace'::regclass;
132+
133+
relhasindex
134+
-----------
135+
f
136+
(1 row)
137+
138+
139+
starting permutation: b2 sfnku2 b1 grant1 addk2 c2 c1 read2
140+
step b2: BEGIN;
141+
step sfnku2:
142+
SELECT relhasindex FROM pg_class
143+
WHERE oid = 'intra_grant_inplace'::regclass FOR NO KEY UPDATE;
144+
145+
relhasindex
146+
-----------
147+
f
148+
(1 row)
149+
150+
step b1: BEGIN;
151+
step grant1:
152+
GRANT SELECT ON intra_grant_inplace TO PUBLIC;
153+
<waiting ...>
154+
step addk2: ALTER TABLE intra_grant_inplace ADD PRIMARY KEY (c);
155+
step c2: COMMIT;
156+
step grant1: <... completed>
157+
step c1: COMMIT;
158+
step read2:
159+
SELECT relhasindex FROM pg_class
160+
WHERE oid = 'intra_grant_inplace'::regclass;
161+
162+
relhasindex
163+
-----------
164+
f
165+
(1 row)
166+
167+
168+
starting permutation: b1 grant1 b3 sfu3 revoke4 c1 r3
169+
step b1: BEGIN;
170+
step grant1:
171+
GRANT SELECT ON intra_grant_inplace TO PUBLIC;
172+
173+
step b3: BEGIN ISOLATION LEVEL READ COMMITTED;
174+
step sfu3:
175+
SELECT relhasindex FROM pg_class
176+
WHERE oid = 'intra_grant_inplace'::regclass FOR UPDATE;
177+
<waiting ...>
178+
step revoke4:
179+
DO $$
180+
BEGIN
181+
REVOKE SELECT ON intra_grant_inplace FROM PUBLIC;
182+
EXCEPTION WHEN others THEN
183+
RAISE WARNING 'got: %', regexp_replace(sqlerrm, '[0-9]+', 'REDACTED');
184+
END
185+
$$;
186+
<waiting ...>
187+
step c1: COMMIT;
188+
step sfu3: <... completed>
189+
relhasindex
190+
-----------
191+
f
192+
(1 row)
193+
194+
s4: WARNING: got: tuple concurrently updated
195+
step revoke4: <... completed>
196+
step r3: ROLLBACK;
197+
198+
starting permutation: b1 drop1 b3 sfu3 revoke4 c1 r3
199+
step b1: BEGIN;
200+
step drop1:
201+
DROP TABLE intra_grant_inplace;
202+
203+
step b3: BEGIN ISOLATION LEVEL READ COMMITTED;
204+
step sfu3:
205+
SELECT relhasindex FROM pg_class
206+
WHERE oid = 'intra_grant_inplace'::regclass FOR UPDATE;
207+
<waiting ...>
208+
step revoke4:
209+
DO $$
210+
BEGIN
211+
REVOKE SELECT ON intra_grant_inplace FROM PUBLIC;
212+
EXCEPTION WHEN others THEN
213+
RAISE WARNING 'got: %', regexp_replace(sqlerrm, '[0-9]+', 'REDACTED');
214+
END
215+
$$;
216+
<waiting ...>
217+
step c1: COMMIT;
218+
step sfu3: <... completed>
219+
relhasindex
220+
-----------
221+
(0 rows)
222+
223+
s4: WARNING: got: tuple concurrently deleted
224+
step revoke4: <... completed>
225+
step r3: ROLLBACK;

src/test/isolation/isolation_schedule

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ test: fk-snapshot
3737
test: subxid-overflow
3838
test: eval-plan-qual
3939
test: eval-plan-qual-trigger
40+
test: inplace-inval
41+
test: intra-grant-inplace
42+
test: intra-grant-inplace-db
4043
test: lock-update-delete
4144
test: lock-update-traversal
4245
test: inherit-temp

0 commit comments

Comments
 (0)