Fix a resource queue lock issue
When ResLockAcquire errors out after proclock is allocated and before the lock
is granted, the 'holdMask' and 'nLocks' of proclock are 0, it should be removed
properly in ResLockRelease.
@@ -316,6 +316,8 @@ ResLockAcquire(LOCKTAG *locktag, ResPortalIncrement *incrementSet)
* Something wrong happened - our RQ is gone. Release all locks and
* clean out
*/
+ lock->nRequested--;
+ lock->requested[lockmode]--;
LWLockReleaseAll();
PG_RE_THROW();
}
@@ -355,6 +357,8 @@ ResLockAcquire(LOCKTAG *locktag, ResPortalIncrement *incrementSet)
incrementSet = ResIncrementAdd(incrementSet, proclock, owner);
if (!incrementSet)
{
+ lock->nRequested--;
+ lock->requested[lockmode]--;
LWLockRelease(ResQueueLock);
LWLockRelease(partitionLock);
ereport(ERROR,
@@ -572,6 +576,7 @@ ResLockRelease(LOCKTAG *locktag, uint32 resPortalId)
LWLockRelease(partitionLock);
elog(DEBUG1, "Resource queue %d: proclock not held", locktag->locktag_field1);
RemoveLocalLock(locallock);
+ ResCleanUpLock(lock, proclock, hashcode, false);
return false;
}
@@ -1482,7 +1487,7 @@ ResIncrementAdd(ResPortalIncrement *incSet, PROCLOCK *proclock, ResourceOwner ow
else
{
/* We have added this portId before - something has gone wrong! */
-
+ ResIncrementRemove(&portaltag);
elog(WARNING, "duplicate portal id %u for proc %d", incSet->portalId, incSet->pid);
incrementSet = NULL;
}
