1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-28 18:48:04 +03:00

Good Bye, Time Travel!

This commit is contained in:
Vadim B. Mikheev
1997-11-02 15:27:14 +00:00
parent 6cc0a00dec
commit 32cd09ac6d
36 changed files with 265 additions and 1841 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.13 1997/09/08 21:41:42 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.14 1997/11/02 15:24:42 vadim Exp $
*
* NOTES
* This file contains the high level access-method interface to the
@@ -41,17 +41,14 @@ TransactionLogUpdate(TransactionId transactionId,
*/
Relation LogRelation = (Relation) NULL;
Relation TimeRelation = (Relation) NULL;
Relation VariableRelation = (Relation) NULL;
/* ----------------
* global variables holding cached transaction id's and statuses.
* ----------------
*/
TransactionId cachedGetCommitTimeXid;
AbsoluteTime cachedGetCommitTime;
TransactionId cachedTestXid;
XidStatus cachedTestXidStatus;
TransactionId cachedTestXid;
XidStatus cachedTestXidStatus;
/* ----------------
* transaction system constants
@@ -118,7 +115,7 @@ SetRecoveryCheckingEnabled(bool state)
#endif
/* ----------------------------------------------------------------
* postgres log/time access method interface
* postgres log access method interface
*
* TransactionLogTest
* TransactionLogUpdate
@@ -204,7 +201,6 @@ TransactionLogUpdate(TransactionId transactionId, /* trans id to update */
{
BlockNumber blockNumber;
bool fail = false; /* success/failure */
AbsoluteTime currentTime; /* time of this transaction */
/* ----------------
* during initialization we don't record any updates.
@@ -213,12 +209,6 @@ TransactionLogUpdate(TransactionId transactionId, /* trans id to update */
if (!RelationIsValid(LogRelation))
return;
/* ----------------
* get the transaction commit time
* ----------------
*/
currentTime = getSystemTime();
/* ----------------
* update the log relation
* ----------------
@@ -234,91 +224,12 @@ TransactionLogUpdate(TransactionId transactionId, /* trans id to update */
* update (invalidate) our single item TransactionLogTest cache.
* ----------------
*/
TransactionIdStore(transactionId, &cachedTestXid);
cachedTestXidStatus = status;
/* ----------------
* now we update the time relation, if necessary
* (we only record commit times)
* ----------------
*/
if (RelationIsValid(TimeRelation) && status == XID_COMMIT)
if (status != XID_COMMIT)
{
TransComputeBlockNumber(TimeRelation, transactionId, &blockNumber);
TransBlockNumberSetCommitTime(TimeRelation,
blockNumber,
transactionId,
currentTime,
&fail);
/* ----------------
* update (invalidate) our single item GetCommitTime cache.
* ----------------
*/
TransactionIdStore(transactionId, &cachedGetCommitTimeXid);
cachedGetCommitTime = currentTime;
TransactionIdStore(transactionId, &cachedTestXid);
cachedTestXidStatus = status;
}
/* ----------------
* now we update the "last committed transaction" field
* in the variable relation if we are recording a commit.
* ----------------
*/
if (RelationIsValid(VariableRelation) && status == XID_COMMIT)
UpdateLastCommittedXid(transactionId);
}
/* --------------------------------
* TransactionIdGetCommitTime
* --------------------------------
*/
AbsoluteTime /* commit time of transaction id */
TransactionIdGetCommitTime(TransactionId transactionId) /* transaction id to
* test */
{
BlockNumber blockNumber;
AbsoluteTime commitTime; /* commit time */
bool fail = false; /* success/failure */
/* ----------------
* return invalid if we aren't running yet...
* ----------------
*/
if (!RelationIsValid(TimeRelation))
return INVALID_ABSTIME;
/* ----------------
* before going to the buffer manager, check our single
* item cache to see if we didn't just get the commit time
* a moment ago.
* ----------------
*/
if (TransactionIdEquals(transactionId, cachedGetCommitTimeXid))
return cachedGetCommitTime;
/* ----------------
* compute the item pointer corresponding to the
* page containing our transaction commit time
* ----------------
*/
TransComputeBlockNumber(TimeRelation, transactionId, &blockNumber);
commitTime = TransBlockNumberGetCommitTime(TimeRelation,
blockNumber,
transactionId,
&fail);
/* ----------------
* update our cache and return the transaction commit time
* ----------------
*/
if (!fail)
{
TransactionIdStore(transactionId, &cachedGetCommitTimeXid);
cachedGetCommitTime = commitTime;
return commitTime;
}
else
return INVALID_ABSTIME;
}
/* ----------------------------------------------------------------
@@ -472,7 +383,6 @@ void
InitializeTransactionLog(void)
{
Relation logRelation;
Relation timeRelation;
MemoryContext oldContext;
/* ----------------
@@ -503,20 +413,17 @@ InitializeTransactionLog(void)
* ----------------
*/
logRelation = heap_openr(LogRelationName);
timeRelation = heap_openr(TimeRelationName);
VariableRelation = heap_openr(VariableRelationName);
/* ----------------
* XXX TransactionLogUpdate requires that LogRelation
* and TimeRelation are valid so we temporarily set
* them so we can initialize things properly.
* This could be done cleaner.
* is valid so we temporarily set it so we can initialize
* things properly. This could be done cleaner.
* ----------------
*/
LogRelation = logRelation;
TimeRelation = timeRelation;
/* ----------------
* if we have a virgin database, we initialize the log and time
* if we have a virgin database, we initialize the log
* relation by committing the AmiTransactionId (id 512) and we
* initialize the variable relation by setting the next available
* transaction id to FirstTransactionId (id 514). OID initialization
@@ -529,10 +436,12 @@ InitializeTransactionLog(void)
/* ----------------
* SOMEDAY initialize the information stored in
* the headers of the log/time/variable relations.
* the headers of the log/variable relations.
* ----------------
*/
TransactionLogUpdate(AmiTransactionId, XID_COMMIT);
TransactionIdStore(AmiTransactionId, &cachedTestXid);
cachedTestXidStatus = XID_COMMIT;
VariableRelationPutNextXid(FirstTransactionId);
}
@@ -547,7 +456,6 @@ InitializeTransactionLog(void)
TransRecover(logRelation);
}
LogRelation = (Relation) NULL;
TimeRelation = (Relation) NULL;
SpinRelease(OidGenLockId);
/* ----------------
@@ -561,7 +469,6 @@ InitializeTransactionLog(void)
* ----------------
*/
LogRelation = logRelation;
TimeRelation = timeRelation;
/* ----------------
* restore the memory context to the previous context
@@ -651,15 +558,7 @@ TransactionIdCommit(TransactionId transactionId)
if (AMI_OVERRIDE)
return;
/*
* Within TransactionLogUpdate we call UpdateLastCommited() which
* assumes we have exclusive access to pg_variable. Therefore we need
* to get exclusive access before calling TransactionLogUpdate. -mer
* 18 Aug 1992
*/
SpinAcquire(OidGenLockId);
TransactionLogUpdate(transactionId, XID_COMMIT);
SpinRelease(OidGenLockId);
}
/*

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.13 1997/09/08 21:41:46 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.14 1997/11/02 15:24:44 vadim Exp $
*
* NOTES
* This file contains support functions for the high
@@ -23,16 +23,10 @@
#include <access/xact.h>
#include <storage/lmgr.h>
static AbsoluteTime
TransBlockGetCommitTime(Block tblock,
TransactionId transactionId);
static XidStatus
TransBlockGetXidStatus(Block tblock,
TransactionId transactionId);
static void
TransBlockSetCommitTime(Block tblock,
TransactionId transactionId, AbsoluteTime commitTime);
static void
TransBlockSetXidStatus(Block tblock,
TransactionId transactionId, XidStatus xstatus);
@@ -73,8 +67,6 @@ TransComputeBlockNumber(Relation relation, /* relation to test */
*/
if (relation == LogRelation)
itemsPerBlock = TP_NumXidStatusPerBlock;
else if (relation == TimeRelation)
itemsPerBlock = TP_NumTimePerBlock;
else
elog(WARN, "TransComputeBlockNumber: unknown relation");
@@ -197,15 +189,6 @@ TransBlockGetXidStatus(Block tblock,
bits8 bit2;
BitIndex offset;
/* ----------------
* sanity check
* ----------------
*/
if (tblock == NULL)
{
return XID_INVALID;
}
/* ----------------
* calculate the index into the transaction data where
* our transaction status is located
@@ -248,13 +231,6 @@ TransBlockSetXidStatus(Block tblock,
Index index;
BitIndex offset;
/* ----------------
* sanity check
* ----------------
*/
if (tblock == NULL)
return;
/* ----------------
* calculate the index into the transaction data where
* we sould store our transaction status.
@@ -295,90 +271,6 @@ TransBlockSetXidStatus(Block tblock,
}
}
/* --------------------------------
* TransBlockGetCommitTime
*
* This returns the transaction commit time for the
* specified transaction id in the trans block.
* --------------------------------
*/
static AbsoluteTime
TransBlockGetCommitTime(Block tblock,
TransactionId transactionId)
{
Index index;
AbsoluteTime *timeArray;
/* ----------------
* sanity check
* ----------------
*/
if (tblock == NULL)
return INVALID_ABSTIME;
/* ----------------
* calculate the index into the transaction data where
* our transaction commit time is located
*
* XXX this will be replaced soon when we move to the
* new transaction id scheme -cim 3/23/90
*
* The new scheme is here. -mer 5/24/92
* ----------------
*/
index = transactionId % TP_NumTimePerBlock;
/* ----------------
* return the commit time to the caller
* ----------------
*/
timeArray = (AbsoluteTime *) tblock;
return (AbsoluteTime)
timeArray[index];
}
/* --------------------------------
* TransBlockSetCommitTime
*
* This sets the commit time of the specified transaction
* --------------------------------
*/
static void
TransBlockSetCommitTime(Block tblock,
TransactionId transactionId,
AbsoluteTime commitTime)
{
Index index;
AbsoluteTime *timeArray;
/* ----------------
* sanity check
* ----------------
*/
if (tblock == NULL)
return;
/* ----------------
* calculate the index into the transaction data where
* we sould store our transaction status.
*
* XXX this will be replaced soon when we move to the
* new transaction id scheme -cim 3/23/90
*
* The new scheme is here. -mer 5/24/92
* ----------------
*/
index = transactionId % TP_NumTimePerBlock;
/* ----------------
* store the transaction commit time at the specified index
* ----------------
*/
timeArray = (AbsoluteTime *) tblock;
timeArray[index] = commitTime;
}
/* ----------------------------------------------------------------
* transam i/o support routines
* ----------------------------------------------------------------
@@ -494,121 +386,6 @@ TransBlockNumberSetXidStatus(Relation relation,
RelationUnsetLockForWrite(relation);
}
/* --------------------------------
* TransBlockNumberGetCommitTime
* --------------------------------
*/
AbsoluteTime
TransBlockNumberGetCommitTime(Relation relation,
BlockNumber blockNumber,
TransactionId xid,
bool *failP)
{
Buffer buffer; /* buffer associated with block */
Block block; /* block containing commit time */
bool localfail; /* bool used if failP = NULL */
AbsoluteTime xtime; /* commit time */
/* ----------------
* SOMEDAY place a read lock on the time relation
*
* That someday is today 5 Aug. 1991 -mer
* ----------------
*/
RelationSetLockForRead(relation);
/* ----------------
* get the block containing the transaction information
* ----------------
*/
buffer = ReadBuffer(relation, blockNumber);
block = BufferGetBlock(buffer);
/* ----------------
* get the commit time from the block
* note, for now we always return false in failP.
* ----------------
*/
if (failP == NULL)
failP = &localfail;
(*failP) = false;
xtime = TransBlockGetCommitTime(block, xid);
/* ----------------
* release the buffer and return the commit time
* ----------------
*/
ReleaseBuffer(buffer);
/* ----------------
* SOMEDAY release our lock on the time relation
* ----------------
*/
RelationUnsetLockForRead(relation);
if ((*failP) == false)
return xtime;
else
return INVALID_ABSTIME;
}
/* --------------------------------
* TransBlockNumberSetCommitTime
* --------------------------------
*/
void
TransBlockNumberSetCommitTime(Relation relation,
BlockNumber blockNumber,
TransactionId xid,
AbsoluteTime xtime,
bool *failP)
{
Buffer buffer; /* buffer associated with block */
Block block; /* block containing commit time */
bool localfail; /* bool used if failP = NULL */
/* ----------------
* SOMEDAY gain exclusive access to the time relation
*
* That someday is today 5 Aug. 1991 -mer
* ----------------
*/
RelationSetLockForWrite(relation);
/* ----------------
* get the block containing our commit time
* ----------------
*/
buffer = ReadBuffer(relation, blockNumber);
block = BufferGetBlock(buffer);
/* ----------------
* attempt to update the commit time of the transaction on the block.
* if we are successful, write the block. otherwise release the buffer.
* note, for now we always return false in failP.
* ----------------
*/
if (failP == NULL)
failP = &localfail;
(*failP) = false;
TransBlockSetCommitTime(block, xid, xtime);
if ((*failP) == false)
WriteBuffer(buffer);
else
ReleaseBuffer(buffer);
/* ----------------
* SOMEDAY release our lock on the time relation
* ----------------
*/
RelationUnsetLockForWrite(relation);
}
/* --------------------------------
* TransGetLastRecordedTransaction
* --------------------------------

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.12 1997/09/08 21:41:49 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.13 1997/11/02 15:24:45 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -23,9 +23,7 @@
static void GetNewObjectIdBlock(Oid *oid_return, int oid_block_size);
static void VariableRelationGetNextOid(Oid *oid_return);
static void VariableRelationGetNextXid(TransactionId *xidP);
static void VariableRelationPutLastXid(TransactionId xid);
static void VariableRelationPutNextOid(Oid *oidP);
static void VariableRelationGetLastXid(TransactionId *xidP);
/* ---------------------
* spin lock for oid generation
@@ -80,49 +78,6 @@ VariableRelationGetNextXid(TransactionId *xidP)
ReleaseBuffer(buf);
}
/* --------------------------------
* VariableRelationGetLastXid
* --------------------------------
*/
static void
VariableRelationGetLastXid(TransactionId *xidP)
{
Buffer buf;
VariableRelationContents var;
/* ----------------
* We assume that a spinlock has been acquire to guarantee
* exclusive access to the variable relation.
* ----------------
*/
/* ----------------
* do nothing before things are initialized
* ----------------
*/
if (!RelationIsValid(VariableRelation))
return;
/* ----------------
* read the variable page, get the the lastXid field and
* release the buffer
* ----------------
*/
buf = ReadBuffer(VariableRelation, 0);
if (!BufferIsValid(buf))
{
SpinRelease(OidGenLockId);
elog(WARN, "VariableRelationGetNextXid: ReadBuffer failed");
}
var = (VariableRelationContents) BufferGetBlock(buf);
TransactionIdStore(var->lastXidData, xidP);
ReleaseBuffer(buf);
}
/* --------------------------------
* VariableRelationPutNextXid
* --------------------------------
@@ -169,49 +124,6 @@ VariableRelationPutNextXid(TransactionId xid)
SetBufferWriteMode(flushmode);
}
/* --------------------------------
* VariableRelationPutLastXid
* --------------------------------
*/
static void
VariableRelationPutLastXid(TransactionId xid)
{
Buffer buf;
VariableRelationContents var;
/* ----------------
* We assume that a spinlock has been acquire to guarantee
* exclusive access to the variable relation.
* ----------------
*/
/* ----------------
* do nothing before things are initialized
* ----------------
*/
if (!RelationIsValid(VariableRelation))
return;
/* ----------------
* read the variable page, update the lastXid field and
* force the page back out to disk.
* ----------------
*/
buf = ReadBuffer(VariableRelation, 0);
if (!BufferIsValid(buf))
{
SpinRelease(OidGenLockId);
elog(WARN, "VariableRelationPutLastXid: ReadBuffer failed");
}
var = (VariableRelationContents) BufferGetBlock(buf);
TransactionIdStore(xid, &(var->lastXidData));
WriteBuffer(buf);
}
/* --------------------------------
* VariableRelationGetNextOid
* --------------------------------
@@ -449,40 +361,6 @@ GetNewTransactionId(TransactionId *xid)
prefetched_xid_count--;
}
/* ----------------
* UpdateLastCommittedXid
* ----------------
*/
void
UpdateLastCommittedXid(TransactionId xid)
{
TransactionId lastid;
/*
* we assume that spinlock OidGenLockId has been acquired prior to
* entering this function
*/
/* ----------------
* get the "last committed" transaction id from
* the variable relation page.
* ----------------
*/
VariableRelationGetLastXid(&lastid);
/* ----------------
* if the transaction id is greater than the last committed
* transaction then we update the last committed transaction
* in the variable relation.
* ----------------
*/
if (TransactionIdIsLessThan(lastid, xid))
VariableRelationPutLastXid(xid);
}
/* ----------------------------------------------------------------
* object id generation support
* ----------------------------------------------------------------

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.16 1997/09/08 21:41:52 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.17 1997/11/02 15:24:46 vadim Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
@@ -497,7 +497,7 @@ CommandCounterIncrement()
if (CurrentTransactionStateData.commandId == FirstCommandId)
{
CommandIdCounterOverflowFlag = true;
elog(WARN, "You may only have 65535 commands per transaction");
elog(WARN, "You may only have 2^32-1 commands per transaction");
}
CurrentTransactionStateData.scanCommandId =

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xid.c,v 1.10 1997/09/08 21:41:56 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xid.c,v 1.11 1997/11/02 15:24:47 vadim Exp $
*
* OLD COMMENTS
* XXX WARNING
@@ -30,18 +30,6 @@ extern TransactionId DisabledTransactionId;
extern TransactionId AmiTransactionId;
extern TransactionId FirstTransactionId;
/* ----------------------------------------------------------------
* TransactionIdIsValid
*
* Macro-ize me.
* ----------------------------------------------------------------
*/
bool
TransactionIdIsValid(TransactionId transactionId)
{
return ((bool) (transactionId != NullTransactionId));
}
/* XXX char16 name for catalogs */
TransactionId
xidin(char *representation)
@@ -65,32 +53,6 @@ xidout(TransactionId transactionId)
}
/* ----------------------------------------------------------------
* StoreInvalidTransactionId
*
* Maybe do away with Pointer types in these routines.
* Macro-ize this one.
* ----------------------------------------------------------------
*/
void
StoreInvalidTransactionId(TransactionId *destination)
{
*destination = NullTransactionId;
}
/* ----------------------------------------------------------------
* TransactionIdStore
*
* Macro-ize this one.
* ----------------------------------------------------------------
*/
void
TransactionIdStore(TransactionId transactionId,
TransactionId *destination)
{
*destination = transactionId;
}
/* ----------------------------------------------------------------
* TransactionIdEquals
* ----------------------------------------------------------------