Skip to content

Commit 44f4986

Browse files
committed
Fix rare deadlock failure in create_am regression test.
The "DROP ACCESS METHOD gist2" test will require locking the index to be dropped and then its table; while most ordinary operations lock a table first then its index. While no concurrent test scripts should be touching fast_emp4000, autovacuum might chance to be processing that table when the DROP runs, resulting in a deadlock failure. This is pretty rare but we see it in the buildfarm from time to time. To fix, acquire a lock on fast_emp4000 before issuing the DROP. Since the point of the exercise is mostly to prevent buildfarm failures, back-patch to 9.6 where this test was introduced. Discussion: https://postgr.es/m/839004.1599185607@sss.pgh.pa.us
1 parent 2a938c7 commit 44f4986

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/test/regress/expected/create_am.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,10 @@ ERROR: cannot drop access method gist2 because other objects depend on it
9999
DETAIL: index grect2ind2 depends on operator class box_ops for access method gist2
100100
HINT: Use DROP ... CASCADE to drop the dependent objects too.
101101
-- Drop access method cascade
102+
-- To prevent a (rare) deadlock against autovacuum,
103+
-- we must lock the table that owns the index that will be dropped
104+
BEGIN;
105+
LOCK TABLE fast_emp4000;
102106
DROP ACCESS METHOD gist2 CASCADE;
103107
NOTICE: drop cascades to index grect2ind2
108+
COMMIT;

src/test/regress/sql/create_am.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ ROLLBACK;
6767
DROP ACCESS METHOD gist2;
6868

6969
-- Drop access method cascade
70+
-- To prevent a (rare) deadlock against autovacuum,
71+
-- we must lock the table that owns the index that will be dropped
72+
BEGIN;
73+
LOCK TABLE fast_emp4000;
7074
DROP ACCESS METHOD gist2 CASCADE;
75+
COMMIT;

0 commit comments

Comments
 (0)