mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Extend relations multiple blocks at a time to improve scalability.
Contention on the relation extension lock can become quite fierce when multiple processes are inserting data into the same relation at the same time at a high rate. Experimentation shows the extending the relation multiple blocks at a time improves scalability. Dilip Kumar, reviewed by Petr Jelinek, Amit Kapila, and me.
This commit is contained in:
@@ -340,6 +340,41 @@ LockRelationForExtension(Relation relation, LOCKMODE lockmode)
|
||||
(void) LockAcquire(&tag, lockmode, false, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* ConditionalLockRelationForExtension
|
||||
*
|
||||
* As above, but only lock if we can get the lock without blocking.
|
||||
* Returns TRUE iff the lock was acquired.
|
||||
*/
|
||||
bool
|
||||
ConditionalLockRelationForExtension(Relation relation, LOCKMODE lockmode)
|
||||
{
|
||||
LOCKTAG tag;
|
||||
|
||||
SET_LOCKTAG_RELATION_EXTEND(tag,
|
||||
relation->rd_lockInfo.lockRelId.dbId,
|
||||
relation->rd_lockInfo.lockRelId.relId);
|
||||
|
||||
return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
|
||||
}
|
||||
|
||||
/*
|
||||
* RelationExtensionLockWaiterCount
|
||||
*
|
||||
* Count the number of processes waiting for the given relation extension lock.
|
||||
*/
|
||||
int
|
||||
RelationExtensionLockWaiterCount(Relation relation)
|
||||
{
|
||||
LOCKTAG tag;
|
||||
|
||||
SET_LOCKTAG_RELATION_EXTEND(tag,
|
||||
relation->rd_lockInfo.lockRelId.dbId,
|
||||
relation->rd_lockInfo.lockRelId.relId);
|
||||
|
||||
return LockWaiterCount(&tag);
|
||||
}
|
||||
|
||||
/*
|
||||
* UnlockRelationForExtension
|
||||
*/
|
||||
|
Reference in New Issue
Block a user