Re: [PATCH] Assert that the correct locks are held when calling PageGetLSN()

From: Asim Praveen <apraveen(at)pivotal(dot)io>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Jacob Champion <pchampion(at)pivotal(dot)io>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Assert that the correct locks are held when calling PageGetLSN()
Date: 2017-11-06 22:27:00
Message-ID: CANXE4TccH_VjdKaHc9=KyH0Y7WORqZN+=mH5f=mP0Bw3gzX1Sw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Michael
On Mon, Oct 2, 2017 at 6:48 PM, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
wrote:
>
> Jacob, here are some ideas to make this thread move on. I would
> suggest to produce a set of patches that do things incrementally:
> 1) One patch that changes the calls of PageGetLSN to
> BufferGetLSNAtomic which are now not appropriate. You have spotted
> some of them in the btree and gist code, but not all based on my first
> lookup. There is still one in gistFindCorrectParent and one in btree
> _bt_split. The monitoring of the other calls (sequence.c and
> vacuumlazy.c) looked safe. There is another one in XLogRecordAssemble
> that should be fixed I think.

Thank you for your suggestions. Please find the first patch attached as
"0001-...". We verified both, gistFindCorrectParent and _bt_split and all
calls to PageGetLSN are made with exclusive lock on the buffer contents
held.

> 2) A second patch that strengthens a bit checks around
> BufferGetLSNAtomic. One idea would be to use LWLockHeldByMe, as you
> are originally suggesting.
> A comment could be as well added in bufpage.h for PageGetLSN to let
> users know that it should be used carefully, in the vein of what is
> mentioned in src/backend/access/transam/README.

The second patch "0002-..." does the above. We have a comment added to
AssertPageIsLockedForLSN as suggested.

The assertion added caught at least one code path where TestForOldSnapshot
calls PageGetLSN without holding any lock. The snapshot_too_old test in
"check-world" failed due to the assertion failure. This needs to be fixed,
see the open question in the opening mail on this thread.

Asim and Jacob

Attachment Content-Type Size
0001-Change-incorrect-calls-to-PageGetLSN-to-BufferGetLSN.patch application/octet-stream 4.1 KB
0002-PageGetLSN-assert-that-locks-are-properly-held.patch application/octet-stream 3.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Юрий Соколов 2017-11-07 00:08:42 Re: Small improvement to compactify_tuples
Previous Message Claudio Freire 2017-11-06 22:14:05 Re: Small improvement to compactify_tuples