diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-08-29 21:02:12 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-08-29 21:02:12 +0000 |
commit | 626eca697cf4470c44cb76f0603302201538c47e (patch) | |
tree | 8acf0b4c0b80977aa189ad75a0434b7f78af80d6 /src/backend/storage/ipc/sinvaladt.c | |
parent | 1761990e385c7d761184425c95c8045303b81084 (diff) | |
download | postgresql-626eca697cf4470c44cb76f0603302201538c47e.tar.gz postgresql-626eca697cf4470c44cb76f0603302201538c47e.zip |
This patch reserves the last superuser_reserved_connections slots for
connections by the superuser only.
This patch replaces the last patch I sent a couple of days ago.
It closes a connection that has not been authorised by a superuser if it would
leave less than the GUC variable ReservedBackends
(superuser_reserved_connections in postgres.conf) backend process slots free
in the SISeg. This differs to the first patch which only reserved the last
ReservedBackends slots in the procState array. This has made the free slot
test more expensive due to the use of a lock.
After thinking about a comment on the first patch I've also made it a fatal
error if the number of reserved slots is not less than the maximum number of
connections.
Nigel J. Andrews
Diffstat (limited to 'src/backend/storage/ipc/sinvaladt.c')
-rw-r--r-- | src/backend/storage/ipc/sinvaladt.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/backend/storage/ipc/sinvaladt.c b/src/backend/storage/ipc/sinvaladt.c index c88055c07b5..b4ab1689f94 100644 --- a/src/backend/storage/ipc/sinvaladt.c +++ b/src/backend/storage/ipc/sinvaladt.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.47 2002/06/20 20:29:35 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.48 2002/08/29 21:02:12 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -60,6 +60,7 @@ SIBufferInit(int maxBackends) segP->maxMsgNum = 0; segP->lastBackend = 0; segP->maxBackends = maxBackends; + segP->freeBackends = maxBackends; /* The buffer[] array is initially all unused, so we need not fill it */ @@ -91,6 +92,13 @@ SIBackendInit(SISeg *segP) int index; ProcState *stateP = NULL; + if (segP->freeBackends == 0) + { + /* out of procState slots */ + MyBackendId = InvalidBackendId; + return 0; + } + /* Look for a free entry in the procState array */ for (index = 0; index < segP->lastBackend; index++) { @@ -103,18 +111,9 @@ SIBackendInit(SISeg *segP) if (stateP == NULL) { - if (segP->lastBackend < segP->maxBackends) - { - stateP = &segP->procState[segP->lastBackend]; - Assert(stateP->nextMsgNum < 0); - segP->lastBackend++; - } - else - { - /* out of procState slots */ - MyBackendId = InvalidBackendId; - return 0; - } + stateP = &segP->procState[segP->lastBackend]; + Assert(stateP->nextMsgNum < 0); + segP->lastBackend++; } MyBackendId = (stateP - &segP->procState[0]) + 1; @@ -123,6 +122,9 @@ SIBackendInit(SISeg *segP) elog(DEBUG1, "SIBackendInit: backend id %d", MyBackendId); #endif /* INVALIDDEBUG */ + /* Reduce free slot count */ + segP->freeBackends--; + /* mark myself active, with all extant messages already read */ stateP->nextMsgNum = segP->maxMsgNum; stateP->resetState = false; @@ -166,6 +168,9 @@ CleanupInvalidationState(int status, Datum arg) } segP->lastBackend = i; + /* Adjust free slot count */ + segP->freeBackends++; + LWLockRelease(SInvalLock); } |