Adding an LWLockHeldByMe()-like function that reports if any buffer content lock is held

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Adding an LWLockHeldByMe()-like function that reports if any buffer content lock is held
Date: 2018-04-18 23:53:29
Message-ID: CAH2-WznJFhRT_b=+M6CcYo4JJacEeDa1meQN2u4+nkWZf5+X7w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

During recent review of the INCLUDE covering index patch, I pushed to
formalize the slightly delicate assumptions that we make around how
index_truncate_tuple() is called. It's natural to call
index_truncate_tuple() during a page split, when a buffer lock is
held. This is what we actually do in most cases.

It occurred to me that it would be nice to be able to
Assert(!AnyBufferLockHeldByMe()) at a certain point within
index_form_tuple(), to make sure that our assumptions hold. If
index_truncate_tuple() (or any other function) ever called
index_form_tuple(), and ended up actually performing table access with
an exclusive buffer lock held, we'd at least be able to catch the bug
when assertions are enabled. A function that lets code assert that no
buffer locks are held, for the rare cases where external table access
is required seems like good general infrastructure.

Does this seem like a good idea? This could get pretty expensive if it
was overused, even by the standards of what we expect from
assertion-enabled builds, but we could make it optional if the
overhead got out of hand.

--
Peter Geoghegan

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2018-04-19 00:04:35 Re: [HACKERS] Runtime Partition Pruning
Previous Message Mark Kirkwood 2018-04-18 23:31:50 Re: PostgreSQL's handling of fsync() errors is unsafe and risks data loss at least on XFS