pgsql: Add API to check if an existing exclusive lock allows cleanup. - Mailing list pgsql-committers

From Robert Haas
Subject pgsql: Add API to check if an existing exclusive lock allows cleanup.
Date
Msg-id E1c2ec6-0007qv-1m@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Add API to check if an existing exclusive lock allows cleanup.

LockBufferForCleanup() acquires a cleanup lock unconditionally, and
ConditionalLockBufferForCleanup() acquires a cleanup lock if it is
possible to do so without waiting; this patch adds a new API,
IsBufferCleanupOK(), which tests whether an exclusive lock already
held happens to be a cleanup lock.  This is possible because a cleanup
lock simply means an exclusive lock plus the assurance any other pins
on the buffer are newer than our own pin.  Therefore, just as the
existing functions decide that the exclusive lock that they've just
taken is a cleanup lock if they observe the pin count to be 1, this
new function allows us to observe that the pin count is 1 on a buffer
we've already locked.

This is useful in situations where a backend definitely wishes to
modify the buffer and also wishes to perform cleanup operations if
possible.  The patch to eliminate heavyweight locking by hash indexes
uses this, and it may have other applications as well.

Amit Kapila, per a suggestion from me.  Some comment adjustments by me
as well.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/f2e6a2ccf1247bc15f6c03895c936b28cdeff181

Modified Files
--------------
src/backend/storage/buffer/bufmgr.c | 49 +++++++++++++++++++++++++++++++++++++
src/include/storage/bufmgr.h        |  1 +
2 files changed, 50 insertions(+)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: postgres_fdw: Fix typo in comment.
Next
From: Peter Eisentraut
Date:
Subject: pgsql: pageinspect: Fix unaligned struct access in GIN functions