aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-07-12 04:11:13 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-07-12 04:11:13 +0000
commitb9f3a929ee6b0309c50d837f464da7440303d2ef (patch)
treec3bd00b8b62a92bbfaf834dda3342df6f90453c6 /src/backend/access/transam
parenteaafc9d66c3196bd0d47cef2b0d8c2cafad504f3 (diff)
downloadpostgresql-b9f3a929ee6b0309c50d837f464da7440303d2ef.tar.gz
postgresql-b9f3a929ee6b0309c50d837f464da7440303d2ef.zip
Create a new HeapTupleSatisfiesVacuum() routine in tqual.c that embodies the
validity checking rules for VACUUM. Make some other rearrangements of the VACUUM code to allow more code to be shared between full and lazy VACUUM. Minor code cleanups and added comments for TransactionId manipulations.
Diffstat (limited to 'src/backend/access/transam')
-rw-r--r--src/backend/access/transam/transam.c40
-rw-r--r--src/backend/access/transam/transsup.c66
-rw-r--r--src/backend/access/transam/varsup.c27
-rw-r--r--src/backend/access/transam/xact.c67
-rw-r--r--src/backend/access/transam/xid.c23
5 files changed, 109 insertions, 114 deletions
diff --git a/src/backend/access/transam/transam.c b/src/backend/access/transam/transam.c
index 89a35b2d335..910042fb624 100644
--- a/src/backend/access/transam/transam.c
+++ b/src/backend/access/transam/transam.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.44 2001/05/14 20:30:19 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.45 2001/07/12 04:11:13 tgl Exp $
*
* NOTES
* This file contains the high level access-method interface to the
@@ -24,6 +24,7 @@
#include "catalog/catname.h"
#include "miscadmin.h"
+
static int RecoveryCheckingEnabled(void);
static void TransRecover(Relation logRelation);
static bool TransactionLogTest(TransactionId transactionId, XidStatus status);
@@ -40,29 +41,11 @@ static void TransactionLogUpdate(TransactionId transactionId,
Relation LogRelation = (Relation) NULL;
/* ----------------
- * global variables holding cached transaction id's and statuses.
- * ----------------
- */
-TransactionId cachedTestXid;
-XidStatus cachedTestXidStatus;
-
-/* ----------------
- * transaction system constants
+ * Single-item cache for results of TransactionLogTest.
* ----------------
*/
-/* ----------------------------------------------------------------
- * transaction system constants
- *
- * read the comments for GetNewTransactionId in order to
- * understand the initial values for AmiTransactionId and
- * FirstTransactionId. -cim 3/23/90
- * ----------------------------------------------------------------
- */
-TransactionId NullTransactionId = (TransactionId) 0;
-
-TransactionId AmiTransactionId = (TransactionId) 512;
-
-TransactionId FirstTransactionId = (TransactionId) 514;
+static TransactionId cachedTestXid = NullTransactionId;
+static XidStatus cachedTestXidStatus;
/* ----------------
* transaction recovery state variables
@@ -76,7 +59,7 @@ TransactionId FirstTransactionId = (TransactionId) 514;
* goes from zero to one. -cim 3/21/90
* ----------------
*/
-int RecoveryCheckingEnableState = 0;
+static int RecoveryCheckingEnableState = 0;
/* ----------------
* recovery checking accessors
@@ -203,14 +186,9 @@ TransactionLogUpdate(TransactionId transactionId, /* trans id to update */
/*
* update (invalidate) our single item TransactionLogTest cache.
- *
- * if (status != XID_COMMIT)
- *
- * What's the hell ?! Why != XID_COMMIT ?!
*/
TransactionIdStore(transactionId, &cachedTestXid);
cachedTestXidStatus = status;
-
}
/* ----------------------------------------------------------------
@@ -355,17 +333,15 @@ InitializeTransactionLog(void)
/*
* if we have a virgin database, we initialize the log relation by
- * committing the AmiTransactionId (id 512) and we initialize the
+ * committing the AmiTransactionId and we initialize the
* variable relation by setting the next available transaction id to
- * FirstTransactionId (id 514). OID initialization happens as a side
+ * FirstTransactionId. OID initialization happens as a side
* effect of bootstrapping in varsup.c.
*/
SpinAcquire(OidGenLockId);
if (!TransactionIdDidCommit(AmiTransactionId))
{
TransactionLogUpdate(AmiTransactionId, XID_COMMIT);
- TransactionIdStore(AmiTransactionId, &cachedTestXid);
- cachedTestXidStatus = XID_COMMIT;
Assert(!IsUnderPostmaster &&
ShmemVariableCache->nextXid <= FirstTransactionId);
ShmemVariableCache->nextXid = FirstTransactionId;
diff --git a/src/backend/access/transam/transsup.c b/src/backend/access/transam/transsup.c
index 0a44a018a9a..3fd6c9d3987 100644
--- a/src/backend/access/transam/transsup.c
+++ b/src/backend/access/transam/transsup.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.30 2001/03/22 06:16:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.31 2001/07/12 04:11:13 tgl Exp $
*
* NOTES
* This file contains support functions for the high
@@ -16,12 +16,67 @@
*
*-------------------------------------------------------------------------
*/
-
#include "postgres.h"
#include "access/xact.h"
#include "utils/bit.h"
+
+/* ----------------
+ * transaction system version id
+ *
+ * this is stored on the first page of the log, time and variable
+ * relations on the first 4 bytes. This is so that if we improve
+ * the format of the transaction log after postgres version 2, then
+ * people won't have to rebuild their databases.
+ *
+ * TRANS_SYSTEM_VERSION 100 means major version 1 minor version 0.
+ * Two databases with the same major version should be compatible,
+ * even if their minor versions differ.
+ *
+ * XXX This isn't actually being used!
+ * ----------------
+ */
+#define TRANS_SYSTEM_VERSION 200
+
+/* ----------------
+ * LogRelationContents structure
+ *
+ * This structure describes the storage of the data in the
+ * first 128 bytes of the log relation. This storage is never
+ * used for transaction status because transaction id's begin
+ * their numbering at 512.
+ *
+ * The first 4 bytes of this relation store the version
+ * number of the transaction system.
+ *
+ * XXX This isn't actually being used!
+ * ----------------
+ */
+typedef struct LogRelationContentsData
+{
+ XLogRecPtr LSN; /* temp hack: LSN is member of any block */
+ /* so should be described in bufmgr */
+ int TransSystemVersion;
+} LogRelationContentsData;
+
+typedef LogRelationContentsData *LogRelationContents;
+
+
+/* ----------------
+ * BitIndexOf computes the index of the Nth xid on a given block
+ * ----------------
+ */
+#define BitIndexOf(N) ((N) * 2)
+
+/* ----------------
+ * transaction page definitions
+ * ----------------
+ */
+#define TP_DataSize (BLCKSZ - sizeof(XLogRecPtr))
+#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
+
+
static XidStatus TransBlockGetXidStatus(Block tblock,
TransactionId transactionId);
static void TransBlockSetXidStatus(Block tblock,
@@ -54,7 +109,7 @@ TransComputeBlockNumber(Relation relation, /* relation to test */
* test */
BlockNumber *blockNumberOutP)
{
- long itemsPerBlock = 0;
+ uint32 itemsPerBlock = 0;
/*
* we calculate the block number of our transaction by dividing the
@@ -135,10 +190,7 @@ TransBlockGetLastTransactionIdStatus(Block tblock,
if (xstatus != XID_INPROGRESS)
{
if (returnXidP != NULL)
- {
- TransactionIdStore(baseXid, returnXidP);
- TransactionIdAdd(returnXidP, index - 1);
- }
+ TransactionIdStore(baseXid + (index - 1), returnXidP);
break;
}
}
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index f245a79cedb..2b253fc5855 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.40 2001/05/25 15:45:32 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.41 2001/07/12 04:11:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,8 +18,7 @@
#include "storage/proc.h"
-/* Number of XIDs and OIDs to prefetch (preallocate) per XLOG write */
-#define VAR_XID_PREFETCH 1024
+/* Number of OIDs to prefetch (preallocate) per XLOG write */
#define VAR_OID_PREFETCH 8192
/* Spinlocks for serializing generation of XIDs and OIDs, respectively */
@@ -29,10 +28,13 @@ SPINLOCK OidGenLockId;
/* pointer to "variable cache" in shared memory (set up by shmem.c) */
VariableCache ShmemVariableCache = NULL;
+
+/*
+ * Allocate the next XID for my new transaction.
+ */
void
GetNewTransactionId(TransactionId *xid)
{
-
/*
* During bootstrap initialization, we return the special bootstrap
* transaction id.
@@ -49,10 +51,22 @@ GetNewTransactionId(TransactionId *xid)
(ShmemVariableCache->nextXid)++;
- SpinRelease(XidGenLockId);
-
+ /*
+ * Must set MyProc->xid before releasing XidGenLock. This ensures that
+ * when GetSnapshotData calls ReadNewTransactionId, all active XIDs
+ * before the returned value of nextXid are already present in the shared
+ * PROC array. Else we have a race condition.
+ *
+ * XXX by storing xid into MyProc without acquiring SInvalLock, we are
+ * relying on fetch/store of an xid to be atomic, else other backends
+ * might see a partially-set xid here. But holding both locks at once
+ * would be a nasty concurrency hit (and at this writing, could cause a
+ * deadlock against GetSnapshotData). So for now, assume atomicity.
+ */
if (MyProc != (PROC *) NULL)
MyProc->xid = *xid;
+
+ SpinRelease(XidGenLockId);
}
/*
@@ -61,7 +75,6 @@ GetNewTransactionId(TransactionId *xid)
void
ReadNewTransactionId(TransactionId *xid)
{
-
/*
* During bootstrap initialization, we return the special bootstrap
* transaction id.
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 4c18ac5a56a..64671792315 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.105 2001/07/06 21:04:25 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.106 2001/07/12 04:11:13 tgl Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
@@ -199,14 +199,9 @@ static void StartTransaction(void);
/* ----------------
* global variables holding the current transaction state.
- *
- * Note: when we are running several slave processes, the
- * current transaction state data is copied into shared memory
- * and the CurrentTransactionState pointer changed to
- * point to the shared copy. All this occurrs in slaves.c
* ----------------
*/
-TransactionStateData CurrentTransactionStateData = {
+static TransactionStateData CurrentTransactionStateData = {
0, /* transaction id */
FirstCommandId, /* command id */
0, /* scan command id */
@@ -234,29 +229,17 @@ static void *_RollbackData = NULL;
* info returned when the system is disabled
*
* Apparently a lot of this code is inherited from other prototype systems.
+ *
* For DisabledStartTime, use a symbolic value to make the relationships clearer.
* The old value of 1073741823 corresponds to a date in y2004, which is coming closer
* every day. It appears that if we return a value guaranteed larger than
* any real time associated with a transaction then comparisons in other
* modules will still be correct. Let's use BIG_ABSTIME for this. tgl 2/14/97
- *
- * Note: I have no idea what the significance of the
- * 1073741823 in DisabledStartTime.. I just carried
- * this over when converting things from the old
- * V1 transaction system. -cim 3/18/90
* ----------------
*/
-TransactionId DisabledTransactionId = (TransactionId) -1;
+static CommandId DisabledCommandId = (CommandId) -1;
-CommandId DisabledCommandId = (CommandId) -1;
-
-AbsoluteTime DisabledStartTime = (AbsoluteTime) BIG_ABSTIME; /* 1073741823; */
-
-/* ----------------
- * overflow flag
- * ----------------
- */
-bool CommandIdCounterOverflowFlag;
+static AbsoluteTime DisabledStartTime = (AbsoluteTime) BIG_ABSTIME;
/* ----------------
* catalog creation transaction bootstrapping flag.
@@ -362,7 +345,7 @@ IsAbortedTransactionBlockState(void)
* themselves.
* --------------------------------
*/
-int SavedTransactionState;
+static int SavedTransactionState;
void
OverrideTransactionSystem(bool flag)
@@ -403,12 +386,12 @@ GetCurrentTransactionId(void)
* "disabled" transaction id.
*/
if (s->state == TRANS_DISABLED)
- return (TransactionId) DisabledTransactionId;
+ return DisabledTransactionId;
/*
* otherwise return the current transaction id.
*/
- return (TransactionId) s->transactionIdData;
+ return s->transactionIdData;
}
@@ -426,7 +409,7 @@ GetCurrentCommandId(void)
* "disabled" command id.
*/
if (s->state == TRANS_DISABLED)
- return (CommandId) DisabledCommandId;
+ return DisabledCommandId;
return s->commandId;
}
@@ -441,7 +424,7 @@ GetScanCommandId(void)
* "disabled" command id.
*/
if (s->state == TRANS_DISABLED)
- return (CommandId) DisabledCommandId;
+ return DisabledCommandId;
return s->scanCommandId;
}
@@ -461,7 +444,7 @@ GetCurrentTransactionStartTime(void)
* "disabled" starting time.
*/
if (s->state == TRANS_DISABLED)
- return (AbsoluteTime) DisabledStartTime;
+ return DisabledStartTime;
return s->startTime;
}
@@ -479,8 +462,7 @@ TransactionIdIsCurrentTransactionId(TransactionId xid)
if (AMI_OVERRIDE)
return false;
- return (bool)
- TransactionIdEquals(xid, s->transactionIdData);
+ return TransactionIdEquals(xid, s->transactionIdData);
}
@@ -512,19 +494,6 @@ CommandIdGEScanCommandId(CommandId cid)
/* --------------------------------
- * ClearCommandIdCounterOverflowFlag
- * --------------------------------
- */
-#ifdef NOT_USED
-void
-ClearCommandIdCounterOverflowFlag(void)
-{
- CommandIdCounterOverflowFlag = false;
-}
-
-#endif
-
-/* --------------------------------
* CommandCounterIncrement
* --------------------------------
*/
@@ -533,10 +502,7 @@ CommandCounterIncrement(void)
{
CurrentTransactionStateData.commandId += 1;
if (CurrentTransactionStateData.commandId == FirstCommandId)
- {
- CommandIdCounterOverflowFlag = true;
elog(ERROR, "You may only have 2^32-1 commands per transaction");
- }
CurrentTransactionStateData.scanCommandId = CurrentTransactionStateData.commandId;
@@ -551,9 +517,7 @@ CommandCounterIncrement(void)
void
SetScanCommandId(CommandId savedId)
{
-
CurrentTransactionStateData.scanCommandId = savedId;
-
}
/* ----------------------------------------------------------------
@@ -1113,6 +1077,13 @@ AbortTransaction(void)
/*
* Let others to know about no transaction in progress - vadim
* 11/26/96
+ *
+ * XXX it'd be nice to acquire SInvalLock for this, but too much risk of
+ * lockup: what if we were holding SInvalLock when we elog'd? Net effect
+ * is that we are relying on fetch/store of an xid to be atomic, else
+ * other backends might see a partially-zeroed xid here. Would it be
+ * safe to release spins before we reset xid/xmin? But see also
+ * GetNewTransactionId, which does the same thing.
*/
if (MyProc != (PROC *) NULL)
{
diff --git a/src/backend/access/transam/xid.c b/src/backend/access/transam/xid.c
index 624d6da850c..9ec40bb2a93 100644
--- a/src/backend/access/transam/xid.c
+++ b/src/backend/access/transam/xid.c
@@ -1,12 +1,12 @@
/*-------------------------------------------------------------------------
*
* xid.c
- * POSTGRES transaction identifier type.
+ * POSTGRES transaction identifier datatype.
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: xid.c,v 1.30 2001/03/22 03:59:18 momjian Exp $
+ * $Id: xid.c,v 1.31 2001/07/12 04:11:13 tgl Exp $
*
* OLD COMMENTS
* XXX WARNING
@@ -30,12 +30,6 @@
#define PG_RETURN_TRANSACTIONID(x) PG_RETURN_UINT32(x)
-extern TransactionId NullTransactionId;
-extern TransactionId DisabledTransactionId;
-extern TransactionId AmiTransactionId;
-extern TransactionId FirstTransactionId;
-
-/* XXX name for catalogs */
Datum
xidin(PG_FUNCTION_ARGS)
{
@@ -44,7 +38,6 @@ xidin(PG_FUNCTION_ARGS)
PG_RETURN_TRANSACTIONID((TransactionId) atol(representation));
}
-/* XXX name for catalogs */
Datum
xidout(PG_FUNCTION_ARGS)
{
@@ -73,15 +66,5 @@ xideq(PG_FUNCTION_ARGS)
TransactionId xid1 = PG_GETARG_TRANSACTIONID(0);
TransactionId xid2 = PG_GETARG_TRANSACTIONID(1);
- PG_RETURN_BOOL(xid1 == xid2);
-}
-
-/* ----------------------------------------------------------------
- * TransactionIdAdd
- * ----------------------------------------------------------------
- */
-void
-TransactionIdAdd(TransactionId *xid, int value)
-{
- *xid += value;
+ PG_RETURN_BOOL(TransactionIdEquals(xid1, xid2));
}