summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc/sinval.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-11-12 20:51:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-11-12 20:51:52 +0000
commitebb0a2014930034a89ae5f4953b52c9afbf585ae (patch)
tree2c8126548b1737e6312c40aa9aecfe9f549f11cb /src/backend/storage/ipc/sinval.c
parentc48025e799dd51a78c82193bc9ce6c63d7e6681f (diff)
Keep track of the last active slot in the shared ProcState array, so
that search loops only have to scan that far and not through all maxBackends entries. This eliminates a performance penalty for setting maxBackends much higher than the average number of active backends. Also, eliminate no-longer-used 'backend tag' concept. Remove setting of environment variables at backend start (except for CYR_RECODE), since none of them are being examined by the backend any longer.
Diffstat (limited to 'src/backend/storage/ipc/sinval.c')
-rw-r--r--src/backend/storage/ipc/sinval.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/backend/storage/ipc/sinval.c b/src/backend/storage/ipc/sinval.c
index c610147fc5f..fb2e4804dd3 100644
--- a/src/backend/storage/ipc/sinval.c
+++ b/src/backend/storage/ipc/sinval.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.22 2000/11/05 22:50:20 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.23 2000/11/12 20:51:51 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -185,6 +185,9 @@ void
/*
* DatabaseHasActiveBackends -- are there any backends running in the given DB
*
+ * If 'ignoreMyself' is TRUE, ignore this particular backend while checking
+ * for backends in the target database.
+ *
* This function is used to interlock DROP DATABASE against there being
* any active backends in the target DB --- dropping the DB while active
* backends remain would be a Bad Thing. Note that we cannot detect here
@@ -194,7 +197,7 @@ void
*/
bool
-DatabaseHasActiveBackends(Oid databaseId)
+DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself)
{
bool result = false;
SISeg *segP = shmInvalBuffer;
@@ -203,7 +206,7 @@ DatabaseHasActiveBackends(Oid databaseId)
SpinAcquire(SInvalLock);
- for (index = 0; index < segP->maxBackends; index++)
+ for (index = 0; index < segP->lastBackend; index++)
{
SHMEM_OFFSET pOffset = stateP[index].procStruct;
@@ -213,6 +216,9 @@ DatabaseHasActiveBackends(Oid databaseId)
if (proc->databaseId == databaseId)
{
+ if (ignoreMyself && proc == MyProc)
+ continue;
+
result = true;
break;
}
@@ -237,7 +243,7 @@ TransactionIdIsInProgress(TransactionId xid)
SpinAcquire(SInvalLock);
- for (index = 0; index < segP->maxBackends; index++)
+ for (index = 0; index < segP->lastBackend; index++)
{
SHMEM_OFFSET pOffset = stateP[index].procStruct;
@@ -275,7 +281,7 @@ GetXmaxRecent(TransactionId *XmaxRecent)
SpinAcquire(SInvalLock);
- for (index = 0; index < segP->maxBackends; index++)
+ for (index = 0; index < segP->lastBackend; index++)
{
SHMEM_OFFSET pOffset = stateP[index].procStruct;
@@ -309,11 +315,11 @@ GetSnapshotData(bool serializable)
int count = 0;
/*
- * There can be no more than maxBackends active transactions, so this
+ * There can be no more than lastBackend active transactions, so this
* is enough space:
*/
snapshot->xip = (TransactionId *)
- malloc(segP->maxBackends * sizeof(TransactionId));
+ malloc(segP->lastBackend * sizeof(TransactionId));
snapshot->xmin = GetCurrentTransactionId();
SpinAcquire(SInvalLock);
@@ -326,7 +332,7 @@ GetSnapshotData(bool serializable)
*/
ReadNewTransactionId(&(snapshot->xmax));
- for (index = 0; index < segP->maxBackends; index++)
+ for (index = 0; index < segP->lastBackend; index++)
{
SHMEM_OFFSET pOffset = stateP[index].procStruct;
@@ -386,7 +392,7 @@ GetUndoRecPtr(void)
SpinAcquire(SInvalLock);
- for (index = 0; index < segP->maxBackends; index++)
+ for (index = 0; index < segP->lastBackend; index++)
{
SHMEM_OFFSET pOffset = stateP[index].procStruct;