Skip to content

Commit 9423299

Browse files
committed
Expand a comment in repack_drop().
Previous text did not sufficiently explain why taking a lock on the target table would be necessary.
1 parent 5317f52 commit 9423299

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/repack.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,19 @@ repack_drop(PG_FUNCTION_ARGS)
950950
repack_init();
951951

952952
/*
953-
* To prevent concurrent lockers of the repack target table from
954-
* causing deadlocks, take an exclusive lock on it.
953+
* To prevent concurrent lockers of the repack target table from causing
954+
* deadlocks, take an exclusive lock on it. Consider that the following
955+
* commands take exclusive lock on tables log_xxx and the target table
956+
* itself when deleting the z_repack_trigger on it, while concurrent
957+
* updaters require row exclusive lock on the target table and in
958+
* addition, on the log_xxx table, because of the trigger.
959+
*
960+
* Consider how a deadlock could occur - if the DROP TABLE repack.log_%u
961+
* gets a lock on log_%u table before a concurrent updater could get it
962+
* but after the updater has obtained a lock on the target table, the
963+
* subsequent DROP TRIGGER ... ON target-table would report a deadlock as
964+
* it finds itself waiting for a lock on target-table held by the updater,
965+
* which in turn, is waiting for lock on log_%u table.
955966
*
956967
* Fixes deadlock mentioned in the Github issue #55.
957968
*/

0 commit comments

Comments
 (0)