Re: possible deadlock: different lock ordering for heap pages

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: "Nishant, Fnu" <nishantf(at)amazon(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: possible deadlock: different lock ordering for heap pages
Date: 2019-01-20 14:54:50
Message-ID: CAA4eK1K4uJ62v3XSNGygn2y7Sv9Ri6UdDBmRkPxSf2DHAk7XUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Jan 19, 2019 at 4:02 AM Nishant, Fnu <nishantf(at)amazon(dot)com> wrote:
>
> Hello,
>
> While locking heap pages (function RelationGetBufferForTuple() in file hio.c) we acquire locks in increasing block number order to avoid deadlock. In certain cases, we do have to drop and reacquire lock on heap pages (when we have to pin visibility map pages) to avoid doing IO while holding exclusive lock. The problem is we now acquire locks in bufferId order, which looks like a slip and the intention was to grab it in block number order. Since it is a trivial change, I am attaching a patch to correct it.
>

On a quick look, your analysis seems correct, but I am bit surprised
to see how this survived so long without being caught. I think you
need to change below code as well if your analysis and fix is correct.
GetVisibilityMapPins()
{
..
Assert(buffer2 == InvalidBuffer || buffer1 <= buffer2);
..
}

AFAICS, this code has been added by below commit, so adding author in the loop.

commit e16954f3d27fa8e16c379ff6623ae18d6250a39c
Author: Robert Haas <rhaas(at)postgresql(dot)org>
Date: Mon Jun 27 13:55:55 2011 -0400

Try again to make the visibility map crash safe.

My previous attempt was quite a bit less than half-baked with respect to
heap_update().

Robert, can you please once see if we are missing anything here
because to me the report and fix look genuine.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-01-20 15:15:53 Re: A small note on the portability of cmake
Previous Message Fabien COELHO 2019-01-20 14:48:14 Re: Alternative to \copy in psql modelled after \g