1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Create VXID locks "lazily" in the main lock table.

Instead of entering them on transaction startup, we materialize them
only when someone wants to wait, which will occur only during CREATE
INDEX CONCURRENTLY.  In Hot Standby mode, the startup process must also
be able to probe for conflicting VXID locks, but the lock need never be
fully materialized, because the startup process does not use the normal
lock wait mechanism.  Since most VXID locks never need to touch the
lock manager partition locks, this can significantly reduce blocking
contention on read-heavy workloads.

Patch by me.  Review by Jeff Davis.
This commit is contained in:
Robert Haas
2011-08-04 12:38:33 -04:00
parent 3b17efdfdd
commit 84e3712677
11 changed files with 257 additions and 95 deletions

View File

@@ -515,70 +515,6 @@ ConditionalXactLockTableWait(TransactionId xid)
return true;
}
/*
* VirtualXactLockTableInsert
*
* Insert a lock showing that the given virtual transaction ID is running ---
* this is done at main transaction start when its VXID is assigned.
* The lock can then be used to wait for the transaction to finish.
*/
void
VirtualXactLockTableInsert(VirtualTransactionId vxid)
{
LOCKTAG tag;
Assert(VirtualTransactionIdIsValid(vxid));
SET_LOCKTAG_VIRTUALTRANSACTION(tag, vxid);
(void) LockAcquire(&tag, ExclusiveLock, false, false);
}
/*
* VirtualXactLockTableWait
*
* Waits until the lock on the given VXID is released, which shows that
* the top-level transaction owning the VXID has ended.
*/
void
VirtualXactLockTableWait(VirtualTransactionId vxid)
{
LOCKTAG tag;
Assert(VirtualTransactionIdIsValid(vxid));
SET_LOCKTAG_VIRTUALTRANSACTION(tag, vxid);
(void) LockAcquire(&tag, ShareLock, false, false);
LockRelease(&tag, ShareLock, false);
}
/*
* ConditionalVirtualXactLockTableWait
*
* As above, but only lock if we can get the lock without blocking.
* Returns TRUE if the lock was acquired.
*/
bool
ConditionalVirtualXactLockTableWait(VirtualTransactionId vxid)
{
LOCKTAG tag;
Assert(VirtualTransactionIdIsValid(vxid));
SET_LOCKTAG_VIRTUALTRANSACTION(tag, vxid);
if (LockAcquire(&tag, ShareLock, false, true) == LOCKACQUIRE_NOT_AVAIL)
return false;
LockRelease(&tag, ShareLock, false);
return true;
}
/*
* LockDatabaseObject
*