提交 624298a9 编写于 作者: A Adam Berlin 提交者: Adam Berlin

Moves the management of the hasResQueueLock into resscheduler.

The only external manipulation of this field occurs in PortalStart,
which we would also like to get rid of, but we're not sure how
at the moment.
Co-authored-by: NAsim R P <apraveen@pivotal.io>
上级 44c52db2
......@@ -358,7 +358,6 @@ PortalCleanup(Portal portal)
*/
if (IsResQueueLockedForPortal(portal))
{
portal->releaseResLock = false;
ResUnLockPortal(portal);
}
......
......@@ -2109,7 +2109,6 @@ _SPI_pquery(QueryDesc *queryDesc, bool fire_triggers, long tcount)
/*
* Checking if we need to put this through resource queue.
* Same as in pquery.c, except we check ActivePortal->releaseResLock.
* If the Active portal already hold a lock on the queue, we cannot
* acquire it again.
*/
......@@ -2136,9 +2135,7 @@ _SPI_pquery(QueryDesc *queryDesc, bool fire_triggers, long tcount)
{
/** TODO: siva - can we ever reach this point? */
ActivePortal->status = PORTAL_QUEUE;
ActivePortal->releaseResLock =
ResLockPortal(ActivePortal, queryDesc);
ResLockPortal(ActivePortal, queryDesc);
ActivePortal->status = PORTAL_ACTIVE;
}
}
......
......@@ -269,7 +269,7 @@ ProcessQuery(Portal portal,
{
portal->status = PORTAL_QUEUE;
portal->releaseResLock = ResLockPortal(portal, queryDesc);
ResLockPortal(portal, queryDesc);
}
else
{
......@@ -597,7 +597,7 @@ PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot,
/* Set up the sequence server */
SetupSequenceServer(seqServerHost, seqServerPort);
portal->releaseResLock = false;
portal->hasResQueueLock = false;
portal->ddesc = ddesc;
......@@ -708,7 +708,7 @@ PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot,
* no additional checks.
*/
if (!SPI_context() || !saveActivePortal || !IsResQueueLockedForPortal(saveActivePortal))
portal->releaseResLock = ResLockPortal(portal, queryDesc);
ResLockPortal(portal, queryDesc);
}
}
......
......@@ -447,7 +447,6 @@ PortalDrop(Portal portal, bool isTopCommit)
if (IsResQueueLockedForPortal(portal))
{
portal->releaseResLock = false;
ResUnLockPortal(portal);
}
......
......@@ -276,7 +276,7 @@ Notes
In the current incarnation of the code it means:
portal->queueId != InvalidOid
portal->releaseResLock == true
portal->hasResQueueLock == true
Typically every portal gets queueId set at creation, but this may get
reset when the to-lock-or-not-to-lock decision comes around (see
......
......@@ -623,7 +623,7 @@ ResLockRelease(LOCKTAG *locktag, uint32 resPortalId)
bool
IsResQueueLockedForPortal(Portal portal) {
return portal->releaseResLock;
return portal->hasResQueueLock;
}
......
......@@ -534,15 +534,11 @@ ResDestroyQueue(Oid queueid)
/*
* ResLockPortal -- get a resource lock for Portal execution.
*
* Returns:
* true if the lock has been taken
* false if the lock has been skipped.
*/
bool
void
ResLockPortal(Portal portal, QueryDesc *qDesc)
{
bool returnReleaseOk = false; /* Release resource lock? */
bool shouldReleaseLock = false; /* Release resource lock? */
bool takeLock; /* Take resource lock? */
LOCKTAG tag;
Oid queueid;
......@@ -581,7 +577,7 @@ ResLockPortal(Portal portal, QueryDesc *qDesc)
if (ResourceSelectOnly)
{
takeLock = false;
returnReleaseOk = false;
shouldReleaseLock = false;
break;
}
}
......@@ -617,7 +613,7 @@ ResLockPortal(Portal portal, QueryDesc *qDesc)
incData.increments[RES_MEMORY_LIMIT] = (Cost) 0.0;
}
takeLock = true;
returnReleaseOk = true;
shouldReleaseLock = true;
}
break;
......@@ -657,7 +653,7 @@ ResLockPortal(Portal portal, QueryDesc *qDesc)
}
takeLock = true;
returnReleaseOk = true;
shouldReleaseLock = true;
}
break;
......@@ -668,7 +664,7 @@ ResLockPortal(Portal portal, QueryDesc *qDesc)
{
takeLock = false;
returnReleaseOk = false;
shouldReleaseLock = false;
}
break;
......@@ -744,27 +740,27 @@ ResLockPortal(Portal portal, QueryDesc *qDesc)
*/
portal->queueId = InvalidOid;
portal->portalId = INVALID_PORTALID;
returnReleaseOk = false;
shouldReleaseLock = false;
}
/* Count holdable cursors (if we are locking this one) .*/
if (portal->cursorOptions & CURSOR_OPT_HOLD && returnReleaseOk)
if (portal->cursorOptions & CURSOR_OPT_HOLD && shouldReleaseLock)
numHoldPortals++;
}
}
return returnReleaseOk;
portal->hasResQueueLock = shouldReleaseLock;
}
/* This function is a simple version of ResLockPortal, which is used specially
* for utility statements; the main logic is same as ResLockPortal, but remove
* some unnecessary lines and make some tiny adjustments for utility stmts */
bool
void
ResLockUtilityPortal(Portal portal, float4 ignoreCostLimit)
{
bool returnReleaseOk = false;
bool shouldReleaseLock = false;
LOCKTAG tag;
Oid queueid;
int32 lockResult = 0;
......@@ -785,7 +781,7 @@ ResLockUtilityPortal(Portal portal, float4 ignoreCostLimit)
incData.increments[RES_COUNT_LIMIT] = 1;
incData.increments[RES_COST_LIMIT] = ignoreCostLimit;
incData.increments[RES_MEMORY_LIMIT] = (Cost) 0.0;
returnReleaseOk = true;
shouldReleaseLock = true;
/*
* Get the resource lock.
......@@ -829,7 +825,8 @@ ResLockUtilityPortal(Portal portal, float4 ignoreCostLimit)
}
PG_END_TRY();
}
return returnReleaseOk;
portal->hasResQueueLock = shouldReleaseLock;
}
/*
......@@ -863,6 +860,8 @@ ResUnLockPortal(Portal portal)
numHoldPortals--;
}
}
portal->hasResQueueLock = false;
return;
}
......@@ -1102,7 +1101,7 @@ ResHandleUtilityStmt(Portal portal, Node *stmt)
{
portal->status = PORTAL_QUEUE;
portal->releaseResLock = ResLockUtilityPortal(portal, resQueue->ignorecostlimit);
ResLockUtilityPortal(portal, resQueue->ignorecostlimit);
}
portal->status = PORTAL_ACTIVE;
}
......
......@@ -147,7 +147,7 @@ typedef struct PortalData
/* Status data */
PortalStatus status; /* see above */
bool releaseResLock; /* true => resscheduler lock must be released */
bool hasResQueueLock; /* true => resscheduler lock must be released */
bool portalPinned; /* a pinned portal can't be dropped */
/* If not NULL, Executor is active; call ExecutorEnd eventually: */
......
......@@ -166,7 +166,7 @@ extern ResAlterQueueResult ResAlterQueue(Oid queueid,
bool overcommit, float4 ignorelimit);
extern bool ResDestroyQueue(Oid queueid);
extern bool ResLockPortal(Portal portal, QueryDesc *qDesc);
extern void ResLockPortal(Portal portal, QueryDesc *qDesc);
extern void ResUnLockPortal(Portal portal);
extern void ResCheckPortalType(Portal portal);
......@@ -178,7 +178,7 @@ extern uint32 ResCreatePortalId(const char *name);
extern void AtCommit_ResScheduler(void);
extern void AtAbort_ResScheduler(void);
extern void ResHandleUtilityStmt(Portal portal, Node *stmt);
extern bool ResLockUtilityPortal(Portal portal, float4 ignoreCostLimit);
extern void ResLockUtilityPortal(Portal portal, float4 ignoreCostLimit);
/**
* What is the memory limit on a queue per the catalog in bytes. Returns -1 if not set.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册