Skip to content

Commit 43b6f3e

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 526df0a commit 43b6f3e

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
@@ -97,5 +97,10 @@ ERROR: cannot drop access method gist2 because other objects depend on it
9797
DETAIL: index grect2ind2 depends on operator class box_ops for access method gist2
9898
HINT: Use DROP ... CASCADE to drop the dependent objects too.
9999
-- Drop access method cascade
100+
-- To prevent a (rare) deadlock against autovacuum,
101+
-- we must lock the table that owns the index that will be dropped
102+
BEGIN;
103+
LOCK TABLE fast_emp4000;
100104
DROP ACCESS METHOD gist2 CASCADE;
101105
NOTICE: drop cascades to index grect2ind2
106+
COMMIT;

src/test/regress/sql/create_am.sql

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

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

0 commit comments

Comments
 (0)