Adjust GetLockConflicts() so that it uses TopMemoryContext when

executed InHotStandby. Cleaner solution than using malloc or palloc
depending upon situation, as proposed by Tom.
This commit is contained in:
Simon Riggs 2010-01-29 19:45:12 +00:00
parent 6d2bc0a6cf
commit 29eedd3122

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.192 2010/01/28 10:05:37 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.193 2010/01/29 19:45:12 sriggs Exp $
* *
* NOTES * NOTES
* A lock table is a shared memory hash table. When * A lock table is a shared memory hash table. When
@ -1790,7 +1790,7 @@ LockReassignCurrentOwner(void)
VirtualTransactionId * VirtualTransactionId *
GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode) GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
{ {
static VirtualTransactionId *vxids = NULL; static VirtualTransactionId *vxids;
LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid; LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid;
LockMethod lockMethodTable; LockMethod lockMethodTable;
LOCK *lock; LOCK *lock;
@ -1810,24 +1810,18 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode)
/* /*
* Allocate memory to store results, and fill with InvalidVXID. We only * Allocate memory to store results, and fill with InvalidVXID. We only
* need enough space for MaxBackends + a terminator, since prepared xacts * need enough space for MaxBackends + a terminator, since prepared xacts
* don't count. * don't count. InHotStandby allocate once in TopMemoryContext.
*/ */
if (!InHotStandby) if (InHotStandby)
{
if (vxids == NULL)
vxids = (VirtualTransactionId *)
MemoryContextAlloc(TopMemoryContext,
sizeof(VirtualTransactionId) * (MaxBackends + 1));
}
else
vxids = (VirtualTransactionId *) vxids = (VirtualTransactionId *)
palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1)); palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1));
else
{
if (vxids == NULL)
{
vxids = (VirtualTransactionId *)
malloc(sizeof(VirtualTransactionId) * (MaxBackends + 1));
if (vxids == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
}
/* /*
* Look up the lock object matching the tag. * Look up the lock object matching the tag.