summaryrefslogtreecommitdiff
path: root/src/backend/access/transam/varsup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/transam/varsup.c')
-rw-r--r--src/backend/access/transam/varsup.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index 885e8e236c..e4271f5fa8 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -6,7 +6,7 @@
* Copyright (c) 2000, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.35 2001/01/24 19:42:51 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.36 2001/03/13 01:17:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -14,12 +14,17 @@
#include "postgres.h"
#include "access/transam.h"
+#include "access/xlog.h"
#include "storage/proc.h"
-SPINLOCK OidGenLockId;
-extern SPINLOCK XidGenLockId;
-extern void XLogPutNextOid(Oid nextOid);
+/* Number of XIDs and OIDs to prefetch (preallocate) per XLOG write */
+#define VAR_XID_PREFETCH 1024
+#define VAR_OID_PREFETCH 8192
+
+/* Spinlocks for serializing generation of XIDs and OIDs, respectively */
+SPINLOCK XidGenLockId;
+SPINLOCK OidGenLockId;
/* pointer to "variable cache" in shared memory (set up by shmem.c) */
VariableCache ShmemVariableCache = NULL;
@@ -38,23 +43,31 @@ GetNewTransactionId(TransactionId *xid)
}
SpinAcquire(XidGenLockId);
+
+ /* If we run out of logged for use xids then we must log more */
+ if (ShmemVariableCache->xidCount == 0)
+ {
+ XLogPutNextXid(ShmemVariableCache->nextXid + VAR_XID_PREFETCH);
+ ShmemVariableCache->xidCount = VAR_XID_PREFETCH;
+ }
+
*xid = ShmemVariableCache->nextXid;
- (ShmemVariableCache->nextXid)++;
- if (MyProc != (PROC *) NULL)
- MyProc->xid = *xid;
+ (ShmemVariableCache->nextXid)++;
+ (ShmemVariableCache->xidCount)--;
SpinRelease(XidGenLockId);
+ if (MyProc != (PROC *) NULL)
+ MyProc->xid = *xid;
}
/*
- * Like GetNewTransactionId reads nextXid but don't fetch it.
+ * Read nextXid but don't allocate it.
*/
void
ReadNewTransactionId(TransactionId *xid)
{
-
/*
* During bootstrap initialization, we return the special
* bootstrap transaction id.
@@ -68,7 +81,6 @@ ReadNewTransactionId(TransactionId *xid)
SpinAcquire(XidGenLockId);
*xid = ShmemVariableCache->nextXid;
SpinRelease(XidGenLockId);
-
}
/* ----------------------------------------------------------------
@@ -76,7 +88,6 @@ ReadNewTransactionId(TransactionId *xid)
* ----------------------------------------------------------------
*/
-#define VAR_OID_PREFETCH 8192
static Oid lastSeenOid = InvalidOid;
void
@@ -84,7 +95,7 @@ GetNewObjectId(Oid *oid_return)
{
SpinAcquire(OidGenLockId);
- /* If we run out of logged for use oids then we log more */
+ /* If we run out of logged for use oids then we must log more */
if (ShmemVariableCache->oidCount == 0)
{
XLogPutNextOid(ShmemVariableCache->nextOid + VAR_OID_PREFETCH);
@@ -103,11 +114,11 @@ GetNewObjectId(Oid *oid_return)
void
CheckMaxObjectId(Oid assigned_oid)
{
-
if (lastSeenOid != InvalidOid && assigned_oid < lastSeenOid)
return;
SpinAcquire(OidGenLockId);
+
if (assigned_oid < ShmemVariableCache->nextOid)
{
lastSeenOid = ShmemVariableCache->nextOid - 1;
@@ -138,5 +149,4 @@ CheckMaxObjectId(Oid assigned_oid)
ShmemVariableCache->nextOid = assigned_oid + 1;
SpinRelease(OidGenLockId);
-
}