pgsql: Fix deadlock between ginDeletePage() and ginStepRight()

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix deadlock between ginDeletePage() and ginStepRight()
Date: 2019-11-19 21:08:59
Message-ID: E1iXAk7-0001eJ-10@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/21ad61ab31786128ae780feca8fcf766bbb6a579

Modified Files
--------------
src/backend/access/gin/README | 79 ++++++++++++++++++++++----------------
src/backend/access/gin/ginvacuum.c | 54 +++++++++++++++++---------
2 files changed, 81 insertions(+), 52 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2019-11-19 21:09:02 pgsql: Fix traversing to the deleted GIN page via downlink
Previous Message Alexander Korotkov 2019-11-19 21:08:55 pgsql: Revise GIN README