Prevent deadlock in ginRedoDeletePage()
authorAlexander Korotkov <akorotkov@postgresql.org>
Thu, 13 Dec 2018 03:12:25 +0000 (06:12 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Thu, 13 Dec 2018 03:55:34 +0000 (06:55 +0300)
commitc6ade7a8cd3135af0c5d29abf39a6a83b9f6a66a
tree048b83cf2d19523ef3c29b2e9a67d1937a1c5dc1
parentfd83c83d0943a6717dbe521efa10da9dce94e4cd
Prevent deadlock in ginRedoDeletePage()

On standby ginRedoDeletePage() can work concurrently with read-only queries.
Those queries can traverse posting tree in two ways.
1) Using rightlinks by ginStepRight(), which locks the next page before
   unlocking its left sibling.
2) Using downlinks by ginFindLeafPage(), which locks at most one page at time.

Original lock order was: page, parent, left sibling.  That lock order can
deadlock with ginStepRight().  In order to prevent deadlock this commit changes
lock order to: left sibling, page, parent.  Note, that position of parent in
locking order seems insignificant, because we only lock one page at time while
traversing downlinks.

Reported-by: Chen Huajun
Diagnosed-by: Chen Huajun, Peter Geoghegan, Andrey Borodin
Discussion: https://postgr.es/m/31a702a.14dd.166c1366ac1.Coremail.chjischj%40163.com
Author: Alexander Korotkov
Backpatch-through: 9.4
src/backend/access/gin/ginxlog.c