Fix deadlock between ginDeletePage() and ginStepRight()

Alexander Korotkov <akorotkov@postgresql.org>

Commit: 051c50c01c32ceb498d53e78f48297713744b7cb
Author: Alexander Korotkov <akorotkov@postgresql.org>
Date: 2019-11-19T21:04:53Z
Releases: 12.2
Fix deadlock between ginDeletePage() and ginStepRight()

When ginDeletePage() is about to delete page it locks its left sibling to revise
the rightlink.  So, it locks pages in right to left manner.  Int he same time
ginStepRight() locks pages in left to right manner, and that could cause a
deadlock.

This commit makes ginScanToDelete() keep exclusive lock on left siblings of
currently investigated path.  That elimites need to relock left sibling in
ginDeletePage().  Thus, deadlock with ginStepRight() can't happen anymore.

Reported-by: Chen Huajun
Discussion: https://postgr.es/m/5c332bd1.87b6.16d7c17aa98.Coremail.chjischj%40163.com
Author: Alexander Korotkov
Reviewed-by: Peter Geoghegan
Backpatch-through: 10

Files

PathChange+/−
src/backend/access/gin/ginvacuum.c modified +35 −19
src/backend/access/gin/README modified +46 −33

Discussion