1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-09 06:21:09 +03:00

Revert the addition of GetMaxBackends() and related stuff.

This reverts commits 0147fc7, 4567596, aa64f23, and 5ecd018.
There is no longer agreement that introducing this function
was the right way to address the problem. The consensus now
seems to favor trying to make a correct value for MaxBackends
available to mdules executing their _PG_init() functions.

Nathan Bossart

Discussion: http://postgr.es/m/20220323045229.i23skfscdbvrsuxa@jrouhaud
This commit is contained in:
Robert Haas
2022-04-12 14:45:23 -04:00
parent 2c9381840f
commit 7fc0e7de9f
19 changed files with 142 additions and 227 deletions

View File

@@ -143,7 +143,6 @@ void
InitDeadLockChecking(void)
{
MemoryContext oldcxt;
int max_backends = GetMaxBackends();
/* Make sure allocations are permanent */
oldcxt = MemoryContextSwitchTo(TopMemoryContext);
@@ -152,16 +151,16 @@ InitDeadLockChecking(void)
* FindLockCycle needs at most MaxBackends entries in visitedProcs[] and
* deadlockDetails[].
*/
visitedProcs = (PGPROC **) palloc(max_backends * sizeof(PGPROC *));
deadlockDetails = (DEADLOCK_INFO *) palloc(max_backends * sizeof(DEADLOCK_INFO));
visitedProcs = (PGPROC **) palloc(MaxBackends * sizeof(PGPROC *));
deadlockDetails = (DEADLOCK_INFO *) palloc(MaxBackends * sizeof(DEADLOCK_INFO));
/*
* TopoSort needs to consider at most MaxBackends wait-queue entries, and
* it needn't run concurrently with FindLockCycle.
*/
topoProcs = visitedProcs; /* re-use this space */
beforeConstraints = (int *) palloc(max_backends * sizeof(int));
afterConstraints = (int *) palloc(max_backends * sizeof(int));
beforeConstraints = (int *) palloc(MaxBackends * sizeof(int));
afterConstraints = (int *) palloc(MaxBackends * sizeof(int));
/*
* We need to consider rearranging at most MaxBackends/2 wait queues
@@ -170,8 +169,8 @@ InitDeadLockChecking(void)
* MaxBackends total waiters.
*/
waitOrders = (WAIT_ORDER *)
palloc((max_backends / 2) * sizeof(WAIT_ORDER));
waitOrderProcs = (PGPROC **) palloc(max_backends * sizeof(PGPROC *));
palloc((MaxBackends / 2) * sizeof(WAIT_ORDER));
waitOrderProcs = (PGPROC **) palloc(MaxBackends * sizeof(PGPROC *));
/*
* Allow at most MaxBackends distinct constraints in a configuration. (Is
@@ -181,7 +180,7 @@ InitDeadLockChecking(void)
* limits the maximum recursion depth of DeadLockCheckRecurse. Making it
* really big might potentially allow a stack-overflow problem.
*/
maxCurConstraints = max_backends;
maxCurConstraints = MaxBackends;
curConstraints = (EDGE *) palloc(maxCurConstraints * sizeof(EDGE));
/*
@@ -192,7 +191,7 @@ InitDeadLockChecking(void)
* last MaxBackends entries in possibleConstraints[] are reserved as
* output workspace for FindLockCycle.
*/
maxPossibleConstraints = max_backends * 4;
maxPossibleConstraints = MaxBackends * 4;
possibleConstraints =
(EDGE *) palloc(maxPossibleConstraints * sizeof(EDGE));
@@ -328,7 +327,7 @@ DeadLockCheckRecurse(PGPROC *proc)
if (nCurConstraints >= maxCurConstraints)
return true; /* out of room for active constraints? */
oldPossibleConstraints = nPossibleConstraints;
if (nPossibleConstraints + nEdges + GetMaxBackends() <= maxPossibleConstraints)
if (nPossibleConstraints + nEdges + MaxBackends <= maxPossibleConstraints)
{
/* We can save the edge list in possibleConstraints[] */
nPossibleConstraints += nEdges;
@@ -389,7 +388,7 @@ TestConfiguration(PGPROC *startProc)
/*
* Make sure we have room for FindLockCycle's output.
*/
if (nPossibleConstraints + GetMaxBackends() > maxPossibleConstraints)
if (nPossibleConstraints + MaxBackends > maxPossibleConstraints)
return -1;
/*
@@ -487,7 +486,7 @@ FindLockCycleRecurse(PGPROC *checkProc,
* record total length of cycle --- outer levels will now fill
* deadlockDetails[]
*/
Assert(depth <= GetMaxBackends());
Assert(depth <= MaxBackends);
nDeadlockDetails = depth;
return true;
@@ -501,7 +500,7 @@ FindLockCycleRecurse(PGPROC *checkProc,
}
}
/* Mark proc as seen */
Assert(nVisitedProcs < GetMaxBackends());
Assert(nVisitedProcs < MaxBackends);
visitedProcs[nVisitedProcs++] = checkProc;
/*
@@ -699,7 +698,7 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
/*
* Add this edge to the list of soft edges in the cycle
*/
Assert(*nSoftEdges < GetMaxBackends());
Assert(*nSoftEdges < MaxBackends);
softEdges[*nSoftEdges].waiter = checkProcLeader;
softEdges[*nSoftEdges].blocker = leader;
softEdges[*nSoftEdges].lock = lock;
@@ -772,7 +771,7 @@ FindLockCycleRecurseMember(PGPROC *checkProc,
/*
* Add this edge to the list of soft edges in the cycle
*/
Assert(*nSoftEdges < GetMaxBackends());
Assert(*nSoftEdges < MaxBackends);
softEdges[*nSoftEdges].waiter = checkProcLeader;
softEdges[*nSoftEdges].blocker = leader;
softEdges[*nSoftEdges].lock = lock;
@@ -835,7 +834,7 @@ ExpandConstraints(EDGE *constraints,
waitOrders[nWaitOrders].procs = waitOrderProcs + nWaitOrderProcs;
waitOrders[nWaitOrders].nProcs = lock->waitProcs.size;
nWaitOrderProcs += lock->waitProcs.size;
Assert(nWaitOrderProcs <= GetMaxBackends());
Assert(nWaitOrderProcs <= MaxBackends);
/*
* Do the topo sort. TopoSort need not examine constraints after this