1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-30 06:01:21 +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:
Robert Haas
2016-04-08 02:04:46 -04:00
parent 8643b91ecf
commit 719c84c1be
7 changed files with 271 additions and 3 deletions

View File

@@ -4380,3 +4380,40 @@ VirtualXactLock(VirtualTransactionId vxid, bool wait)
LockRelease(&tag, ShareLock, false);
return true;
}
/*
* LockWaiterCount
*
* Find the number of lock requester on this locktag
*/
int
LockWaiterCount(const LOCKTAG *locktag)
{
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LOCK *lock;
bool found;
uint32 hashcode;
LWLock *partitionLock;
int waiters = 0;
if (lockmethodid <= 0 || lockmethodid >= lengthof(LockMethods))
elog(ERROR, "unrecognized lock method: %d", lockmethodid);
hashcode = LockTagHashCode(locktag);
partitionLock = LockHashPartitionLock(hashcode);
LWLockAcquire(partitionLock, LW_EXCLUSIVE);
lock = (LOCK *) hash_search_with_hash_value(LockMethodLockHash,
(const void *) locktag,
hashcode,
HASH_FIND,
&found);
if (found)
{
Assert(lock != NULL);
waiters = lock->nRequested;
}
LWLockRelease(partitionLock);
return waiters;
}