head	1.19;
access;
symbols
	release_4_2:1.19
	aix_ok:1.19
	Version_2_1:1.6;
locks; strict;
comment	@ * @;


1.19
date	93.07.16.18.42.26;	author avi;	state Exp;
branches;
next	1.18;

1.18
date	93.07.01.22.55.03;	author avi;	state Exp;
branches;
next	1.17;

1.17
date	93.03.18.19.10.45;	author aoki;	state Exp;
branches;
next	1.16;

1.16
date	92.08.13.23.26.25;	author mer;	state Exp;
branches;
next	1.15;

1.15
date	92.08.13.23.21.21;	author mer;	state Exp;
branches;
next	1.14;

1.14
date	92.08.03.23.05.02;	author mao;	state Exp;
branches;
next	1.13;

1.13
date	92.07.22.23.12.23;	author mao;	state Exp;
branches;
next	1.12;

1.12
date	92.05.28.20.20.52;	author mer;	state Exp;
branches;
next	1.11;

1.11
date	92.04.13.18.35.30;	author mer;	state Exp;
branches;
next	1.10;

1.10
date	92.02.19.01.51.53;	author mer;	state Exp;
branches;
next	1.9;

1.9
date	91.11.08.15.42.13;	author kemnitz;	state Exp;
branches;
next	1.8;

1.8
date	91.05.23.18.13.58;	author kemnitz;	state Exp;
branches;
next	1.7;

1.7
date	91.04.28.09.17.03;	author cimarron;	state Exp;
branches;
next	1.6;

1.6
date	91.02.06.18.17.40;	author cimarron;	state Exp;
branches;
next	1.5;

1.5
date	90.10.19.17.08.02;	author mao;	state Exp;
branches;
next	1.4;

1.4
date	90.09.25.16.18.26;	author kemnitz;	state Exp;
branches;
next	1.3;

1.3
date	90.04.11.00.28.27;	author kemnitz;	state Exp;
branches;
next	1.2;

1.2
date	90.03.26.20.34.01;	author cimarron;	state Exp;
branches;
next	1.1;

1.1
date	90.03.22.13.02.29;	author cimarron;	state Exp;
branches;
next	;


desc
@new improved transaction access methods support
@


1.19
log
@time cleanup
@
text
@/* ----------------------------------------------------------------
 *   FILE
 *	transam.c
 *	
 *   DESCRIPTION
 *	postgres transaction log/time interface routines
 *
 *   INTERFACE ROUTINES
 *	RecoveryCheckingEnabled
 *	SetRecoveryCheckingEnabled
 *	InitializeTransactionLog
 *	TransactionIdDidCommit
 *	TransactionIdDidAbort
 *	TransactionIdIsInProgress
 *	TransactionIdCommit
 *	TransactionIdAbort
 *	TransactionIdSetInProgress
 *   	
 *   NOTES
 *	This file contains the high level access-method
 *	interface to the transaction system.
 *
 *   IDENTIFICATION
 *	$Header: /private/src/postgres/src/backend/access/transam/RCS/transam.c,v 1.18 1993/07/01 22:55:03 avi Exp avi $
 * ----------------------------------------------------------------
 */

#include "tmp/postgres.h"

 RcsId("$Header: /private/src/postgres/src/backend/access/transam/RCS/transam.c,v 1.18 1993/07/01 22:55:03 avi Exp avi $");

#include "machine.h"		/* in port/ directory (needed for BLCKSZ) */

#include "access/heapam.h"
#include "storage/buf.h"
#include "storage/bufmgr.h"

#include "utils/memutils.h"
#include "utils/mcxt.h"
#include "utils/rel.h"
#include "utils/log.h"

#include "utils/nabstime.h"
#include "catalog/catname.h"

#include "access/transam.h"
#include "access/xact.h"

/* ----------------
 *    global variables holding pointers to relations used
 *    by the transaction system.  These are initialized by
 *    InitializeTransactionLog().
 * ----------------
 */

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;

/* ----------------
 *	transaction system constants
 * ----------------
 */
TransactionId NullTransactionId = (TransactionId) 0;

TransactionId AmiTransactionId = (TransactionId) 512;

TransactionId FirstTransactionId = (TransactionId) 514;

/* ----------------
 *	transaction recovery state variables
 *
 *	When the transaction system is initialized, we may
 *	need to do recovery checking.  This decision is decided
 *	by the postmaster or the user by supplying the backend
 *	with a special flag.  In general, we want to do recovery
 *	checking whenever we are running without a postmaster
 *	or when the number of backends running under the postmaster
 *	goes from zero to one. -cim 3/21/90
 * ----------------
 */
int RecoveryCheckingEnableState = 0;

/* ------------------
 *	spinlock for oid generation
 * -----------------
 */
extern int OidGenLockId;

/* ----------------
 *	globals that must be reset at abort
 * ----------------
 */
extern bool	BuildingBtree;
extern bool	VacuumRunning;

/* ----------------
 *	recovery checking accessors
 * ----------------
 */
int
RecoveryCheckingEnabled()
{    
    return RecoveryCheckingEnableState;
}

void
SetRecoveryCheckingEnabled(state)
    bool state;
{    
    RecoveryCheckingEnableState = (state == true);
}

/* ----------------------------------------------------------------
 *	postgres log/time access method interface
 *
 *	TransactionLogTest
 *	TransactionLogUpdate
 *	========
 *	   these functions do work for the interface
 *	   functions - they search/retrieve and append/update
 *	   information in the log and time relations.
 * ----------------------------------------------------------------
 */

/* --------------------------------
 *	TransactionLogTest
 * --------------------------------
 */

bool	/* true/false: does transaction id have specified status? */
TransactionLogTest(transactionId, status)
    TransactionId 	transactionId; 	/* transaction id to test */
    XidStatus 		status;		/* transaction status */
{
    BlockNumber		blockNumber;
    XidStatus		xidstatus;	/* recorded status of xid */
    bool		fail = false;      	/* success/failure */
    
    /* ----------------
     * 	during initialization consider all transactions
     *  as having been committed
     * ----------------
     */
    if (! RelationIsValid(LogRelation))
	return (bool) (status == XID_COMMIT);

    /* ----------------
     *	 before going to the buffer manager, check our single
     *   item cache to see if we didn't just check the transaction
     *   status a moment ago.
     * ----------------
     */
    if (TransactionIdEquals(transactionId, cachedTestXid))
	return (bool)
	    (status == cachedTestXidStatus);
        
    /* ----------------
     *	compute the item pointer corresponding to the
     *  page containing our transaction id.  We save the item in
     *  our cache to speed up things if we happen to ask for the
     *  same xid's status more than once.
     * ----------------
     */
    TransComputeBlockNumber(LogRelation, transactionId, &blockNumber);
    xidstatus = TransBlockNumberGetXidStatus(LogRelation,
					     blockNumber,
					     transactionId,
					     &fail);

    if (! fail) {
	TransactionIdStore(transactionId, &cachedTestXid);
	cachedTestXidStatus = xidstatus;
	return (bool)
	    (status == xidstatus);
    }
    
    /* ----------------
     *	  here the block didn't contain the information we wanted
     * ----------------
     */
    elog(WARN, "TransactionLogTest: failed to get xidstatus");

    /*
     * so lint is happy...
     */
    return(false);
}

/* --------------------------------
 *	TransactionLogUpdate
 * --------------------------------
 */
void
TransactionLogUpdate(transactionId, status)
    TransactionId 	transactionId;	/* trans id to update */
    XidStatus 		status;		/* new trans status */
{
    BlockNumber		blockNumber;
    bool		fail = false;      	/* success/failure */
    AbsoluteTime	currentTime;	/* time of this transaction */

    /* ----------------
     * 	during initialization we don't record any updates.
     * ----------------
     */
    if (! RelationIsValid(LogRelation))
	return;
    
    /* ----------------
     *  get the transaction commit time
     * ----------------
     */
    currentTime = GetSystemTime();

    /* ----------------
     *  update the log relation
     * ----------------
     */
    TransComputeBlockNumber(LogRelation, transactionId, &blockNumber);
    TransBlockNumberSetXidStatus(LogRelation,
				 blockNumber,
				 transactionId,
				 status,
				 &fail);

    /* ----------------
     *	 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) {
	TransComputeBlockNumber(TimeRelation, transactionId, &blockNumber);
	TransBlockNumberSetCommitTime(TimeRelation,
				      blockNumber,
				      transactionId,
				      currentTime,
				      &fail);
	/* ----------------
	 *   update (invalidate) our single item GetCommitTime cache.
	 * ----------------
	 */
	TransactionIdStore(transactionId, &cachedGetCommitTimeXid);
	cachedGetCommitTime = currentTime;
    }

    /* ----------------
     *	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 	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;
}

/* ----------------------------------------------------------------
 *		     transaction recovery code
 * ----------------------------------------------------------------
 */

/* --------------------------------
 *	TransRecover
 *
 *    	preform transaction recovery checking.
 *
 *	Note: this should only be preformed if no other backends
 *	      are running.  This is known by the postmaster and
 *	      conveyed by the postmaster passing a "do recovery checking"
 *	      flag to the backend.
 *
 *	here we get the last recorded transaction from the log,
 *	get the "last" and "next" transactions from the variable relation
 *	and then preform some integrity tests:
 *
 *    	1) No transaction may exist higher then the "next" available
 *         transaction recorded in the variable relation.  If this is the
 *         case then it means either the log or the variable relation
 *         has become corrupted.
 *
 *      2) The last committed transaction may not be higher then the
 *         next available transaction for the same reason.
 *
 *      3) The last recorded transaction may not be lower then the
 *         last committed transaction.  (the reverse is ok - it means
 *         that some transactions have aborted since the last commit)
 *
 *	Here is what the proper situation looks like.  The line
 *	represents the data stored in the log.  'c' indicates the
 *      transaction was recorded as committed, 'a' indicates an
 *      abortted transaction and '.' represents information not
 *      recorded.  These may correspond to in progress transactions.
 *
 *	     c  c  a  c  .  .  a  .  .  .  .  .  .  .  .  .  .
 *		      |                 |
 *		     last	       next
 *
 *	Since "next" is only incremented by GetNewTransactionId() which
 *      is called when transactions are started.  Hence if there
 *      are commits or aborts after "next", then it means we committed
 *      or aborted BEFORE we started the transaction.  This is the
 *	rational behind constraint (1).
 *
 *      Likewise, "last" should never greater then "next" for essentially
 *      the same reason - it would imply we committed before we started.
 *      This is the reasoning for (2).
 *
 *	(3) implies we may never have a situation such as:
 *
 *	     c  c  a  c  .  .  a  c  .  .  .  .  .  .  .  .  .
 *		      |                 |
 *		     last	       next
 *
 *      where there is a 'c' greater then "last".
 *
 *      Recovery checking is more difficult in the case where
 *      several backends are executing concurrently because the
 *	transactions may be executing in the other backends.
 *      So, we only do recovery stuff when the backend is explicitly
 *      passed a flag on the command line.
 * --------------------------------
 */

void
TransRecover(logRelation)
    Relation logRelation;
{
    TransactionId logLastXid;
    TransactionId varLastXid;
    TransactionId varNextXid;

#if 0    
    /* ----------------
     *    first get the last recorded transaction in the log.
     * ----------------
     */
    TransGetLastRecordedTransaction(logRelation, logLastXid, &fail);
    if (fail == true)
	elog(WARN, "TransRecover: failed TransGetLastRecordedTransaction");
    
    /* ----------------
     *    next get the "last" and "next" variables
     * ----------------
     */
    VariableRelationGetLastXid(&varLastXid);
    VariableRelationGetNextXid(&varNextXid);

    /* ----------------
     *    intregity test (1)
     * ----------------
     */
    if (TransactionIdIsLessThan(varNextXid, logLastXid))
	elog(WARN, "TransRecover: varNextXid < logLastXid");
	    
    /* ----------------
     *    intregity test (2)
     * ----------------
     */
	    	
    /* ----------------
     *    intregity test (3)
     * ----------------
     */

    /* ----------------
     *  here we have a valid "
     *
     *		**** RESUME HERE ****
     * ----------------
     */
    varNextXid = TransactionIdDup(varLastXid);
    TransactionIdIncrement(&varNextXid);

    VarPut(var, VAR_PUT_LASTXID, varLastXid);
    VarPut(var, VAR_PUT_NEXTXID, varNextXid);
#endif
}
    
/* ----------------------------------------------------------------
 *			Interface functions
 *
 *	InitializeTransactionLog
 *	========
 *	   this function (called near cinit) initializes
 *	   the transaction log, time and variable relations.
 *
 *	TransactionId DidCommit
 *	TransactionId DidAbort
 *	TransactionId IsInProgress
 *	========
 *	   these functions test the transaction status of
 *	   a specified transaction id.
 *
 *	TransactionId Commit
 *	TransactionId Abort
 *	TransactionId SetInProgress
 *	========
 *	   these functions set the transaction status
 *	   of the specified xid. TransactionIdCommit() also
 *	   records the current time in the time relation
 *	   and updates the variable relation counter.
 *
 * ----------------------------------------------------------------
 */

/* --------------------------------
 *	InitializeTransactionLog
 * --------------------------------
 */

void
InitializeTransactionLog()
{
    Relation	  logRelation;
    Relation	  timeRelation;
    Relation	  varRelation;
    MemoryContext oldContext;
    BlockNumber	  n;
    bool	  fail = false;
    
    /* ----------------
     *    don't do anything during bootstrapping
     * ----------------
     */
    if (AMI_OVERRIDE)
	return;
    
    /* ----------------
     *	 disable the transaction system so the access methods
     *   don't interfere during initialization.
     * ----------------
     */
    OverrideTransactionSystem(true);
    
    /* ----------------
     *	make sure allocations occur within the top memory context
     *  so that our log management structures are protected from
     *  garbage collection at the end of every transaction.
     * ----------------
     */
    oldContext = MemoryContextSwitchTo(TopMemoryContext); 
    
    /* ----------------
     *   first open the log and time relations
     *   (these are created by amiint so they are guaranteed to exist)
     * ----------------
     */
    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.
    * ----------------
    */
    LogRelation =  logRelation;
    TimeRelation = timeRelation;

    /* ----------------
     *   if we have a virgin database, we initialize the log and time
     *	 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
     *   happens as a side effect of bootstrapping in varsup.c.
     * ----------------
     */
    SpinAcquire(OidGenLockId);
    if (!TransactionIdDidCommit(AmiTransactionId)) {

	/* ----------------
	 *  SOMEDAY initialize the information stored in
	 *          the headers of the log/time/variable relations.
	 * ----------------
	 */
	TransactionLogUpdate(AmiTransactionId, XID_COMMIT);
	VariableRelationPutNextXid(FirstTransactionId);
	
    } else if (RecoveryCheckingEnabled()) {
	/* ----------------
	 *	if we have a pre-initialized database and if the
	 *	perform recovery checking flag was passed then we
	 *	do our database integrity checking.
	 * ----------------
	 */
	TransRecover(logRelation);
    }
    LogRelation =  (Relation) NULL;
    TimeRelation = (Relation) NULL;
    SpinRelease(OidGenLockId);
    
    /* ----------------
     *	now re-enable the transaction system
     * ----------------
     */
    OverrideTransactionSystem(false);
    
    /* ----------------
     *	instantiate the global variables
     * ----------------
     */
    LogRelation = 	logRelation;
    TimeRelation = 	timeRelation;

    /* ----------------
     *	restore the memory context to the previous context
     *  before we return from initialization.
     * ----------------
     */
    MemoryContextSwitchTo(oldContext);
}

/* --------------------------------
 *	TransactionId DidCommit
 *	TransactionId DidAbort
 *	TransactionId IsInProgress
 * --------------------------------
 */

bool	/* true if given transaction committed */
TransactionIdDidCommit(transactionId)
    TransactionId transactionId;
{
    if (AMI_OVERRIDE)
	return true;
    
    return
	TransactionLogTest(transactionId, XID_COMMIT);
}

bool	/* true if given transaction aborted */
TransactionIdDidAbort(transactionId)
    TransactionId transactionId;
{
    if (AMI_OVERRIDE)
	return false;
    
    return
	TransactionLogTest(transactionId, XID_ABORT);
}

bool	/* true if given transaction neither committed nor aborted */
TransactionIdIsInProgress(transactionId)
    TransactionId transactionId;
{
    if (AMI_OVERRIDE)
	return false;
    
    return
	TransactionLogTest(transactionId, XID_INPROGRESS);
}

/* --------------------------------
 *	TransactionId Commit
 *	TransactionId Abort
 *	TransactionId SetInProgress
 * --------------------------------
 */

void
TransactionIdCommit(transactionId)
    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);
}

void
TransactionIdAbort(transactionId)
    TransactionId transactionId;
{
    BuildingBtree = false;

    if (VacuumRunning)
	vc_abort();

    if (AMI_OVERRIDE)
	return;
    
    TransactionLogUpdate(transactionId, XID_ABORT);
}

void
TransactionIdSetInProgress(transactionId)
    TransactionId transactionId;
{
    if (AMI_OVERRIDE)
	return;
    
    TransactionLogUpdate(transactionId, XID_INPROGRESS);
}
@


1.18
log
@got rid of InvalidTime
@
text
@d24 1
a24 1
 *	$Header: /private/src/postgres/src/backend/access/transam/RCS/transam.c,v 1.17 1993/03/18 19:10:45 aoki Exp avi $
d30 1
a30 1
 RcsId("$Header: /private/src/postgres/src/backend/access/transam/RCS/transam.c,v 1.17 1993/03/18 19:10:45 aoki Exp avi $");
d65 1
a65 1
Time 		cachedGetCommitTime;
d210 1
a210 1
    Time 		currentTime;	/* time of this transaction */
d277 1
a277 1
Time  /* commit time of transaction id */
d282 1
a282 1
    Time		commitTime;     /* commit time */
@


1.17
log
@added a missing argument (the routine called if #if 0'd out
anyway, but cc on alpha whines..)
@
text
@d24 1
a24 1
 *	$Header: /home2/aoki/postgres/src/backend/access/transam/RCS/transam.c,v 1.16 1992/08/13 23:26:25 mer Exp aoki $
d30 1
a30 1
 RcsId("$Header: /home2/aoki/postgres/src/backend/access/transam/RCS/transam.c,v 1.16 1992/08/13 23:26:25 mer Exp aoki $");
d290 1
a290 1
	return InvalidTime;
d321 1
a321 1
	return InvalidTime;
@


1.16
log
@prev message was a misnomer - i have only added some comments here, the
bottom line is that we needed exclusive access to *pg_variable* not pg_log
@
text
@d24 1
a24 1
 *	$Header: /private/mer/pg/src/access/transam/RCS/transam.c,v 1.15 1992/08/13 23:21:21 mer Exp mer $
d30 1
a30 1
 RcsId("$Header: /private/mer/pg/src/access/transam/RCS/transam.c,v 1.15 1992/08/13 23:21:21 mer Exp mer $");
d512 1
a512 1
     *   (these are created by amiint so they are guarantted to exist)
d550 1
a550 1
	 *	preform recovery checking flag was passed then we
d554 1
a554 1
	TransRecover();
@


1.15
log
@get exclusive access to update pg_log before twiddling the bits there.
@
text
@d24 1
a24 1
 *	$Header: /private/mer/pg/src/access/transam/RCS/transam.c,v 1.14 1992/08/03 23:05:02 mao Exp mer $
d30 1
a30 1
 RcsId("$Header: /private/mer/pg/src/access/transam/RCS/transam.c,v 1.14 1992/08/03 23:05:02 mao Exp mer $");
d635 6
@


1.14
log
@if we abort while vacuuming the db, need to remove the lock file
created by the vacuum cleaner.
@
text
@d24 1
a24 1
 *	$Header: /private/mao/postgres/src/access/transam/RCS/transam.c,v 1.13 1992/07/22 23:12:23 mao Exp mao $
d30 1
a30 1
 RcsId("$Header: /private/mao/postgres/src/access/transam/RCS/transam.c,v 1.13 1992/07/22 23:12:23 mao Exp mao $");
d635 1
d637 1
@


1.13
log
@on xact abort, reset an important btree global var to false.
@
text
@d24 1
a24 1
 *	$Header: /private/mao/postgres/src/access/transam/RCS/transam.c,v 1.12 1992/05/28 20:20:52 mer Exp $
d30 1
a30 1
 RcsId("$Header: /private/mao/postgres/src/access/transam/RCS/transam.c,v 1.12 1992/05/28 20:20:52 mer Exp $");
d104 1
d643 3
@


1.12
log
@Transaction ids are now longs and command ids are now shorts
@
text
@d24 1
a24 1
 *	$Header: /private/mer/pg.latest/src/access/transam/RCS/transam.c,v 1.11 1992/04/13 18:35:30 mer Exp mer $
d30 1
a30 1
 RcsId("$Header: /private/mer/pg.latest/src/access/transam/RCS/transam.c,v 1.11 1992/04/13 18:35:30 mer Exp mer $");
d98 7
d641 2
@


1.11
log
@change test for virgin database -- check commit time on amitransaction id
@
text
@d24 1
a24 1
 *	$Header: /users/mer/pg/src/access/transam/RCS/transam.c,v 1.10 1992/02/19 01:51:53 mer Exp mer $
d30 1
a30 1
 RcsId("$Header: /users/mer/pg/src/access/transam/RCS/transam.c,v 1.10 1992/02/19 01:51:53 mer Exp mer $");
d64 4
a67 4
TransactionIdData cachedGetCommitTimeXid;
Time 		  cachedGetCommitTime;
TransactionIdData cachedTestXid;
XidStatus	  cachedTestXidStatus;
d73 1
a73 2
static TransactionIdData NullTransactionIdData = { { 0, 0, 0, 0, 0 } };
TransactionId NullTransactionId = &NullTransactionIdData;
d75 1
a75 2
static TransactionIdData TransactionIdOneData = { { 0, 0, 0, 2, 0 } };
TransactionId AmiTransactionId = &TransactionIdOneData;
d77 1
a77 2
static TransactionIdData FirstTransactionIdData = { { 0, 0, 0, 2, 2 } };
TransactionId FirstTransactionId = &FirstTransactionIdData;
d155 1
a155 1
    if (TransactionIdEquals(transactionId, &cachedTestXid))
d173 1
a173 1
	TransactionIdStore(transactionId, (Pointer) &cachedTestXid);
d232 1
a232 1
    TransactionIdStore(transactionId, (Pointer) &cachedTestXid);
d251 1
a251 1
	TransactionIdStore(transactionId, (Pointer) &cachedGetCommitTimeXid);
d290 1
a290 1
    if (TransactionIdEquals(transactionId, &cachedGetCommitTimeXid))
d309 1
a309 1
	TransactionIdStore(transactionId, (Pointer) &cachedGetCommitTimeXid);
d404 2
a405 2
    VariableRelationGetLastXid(varLastXid);
    VariableRelationGetNextXid(varNextXid);
d431 1
a431 1
    TransactionIdIncrement(varNextXid);
@


1.10
log
@changes for the new abstime implementation
@
text
@d24 1
a24 1
 *	$Header: /users/mer/pg/src/access/transam/RCS/transam.c,v 1.9 1991/11/08 15:42:13 kemnitz Exp mer $
d30 1
a30 1
 RcsId("$Header: /users/mer/pg/src/access/transam/RCS/transam.c,v 1.9 1991/11/08 15:42:13 kemnitz Exp mer $");
d96 5
d513 9
d531 2
a532 11
    n = RelationGetNumberOfBlocks(logRelation);
    if (n == 0) {
	/* ----------------
	 *   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.
	 * ----------------
	 */
	LogRelation =  logRelation;
	TimeRelation = timeRelation;
a541 3
	LogRelation =  (Relation) NULL;
	TimeRelation = (Relation) NULL;
	
d551 3
@


1.9
log
@fixed prototypes
@
text
@d24 1
a24 1
 *	$Header: RCS/transam.c,v 1.8 91/05/23 18:13:58 kemnitz Exp Locker: kemnitz $
d30 1
a30 1
 RcsId("$Header: RCS/transam.c,v 1.8 91/05/23 18:13:58 kemnitz Exp Locker: kemnitz $");
d43 1
a43 1
#include "tmp/miscadmin.h"
@


1.8
log
@got rid of has return(e); and return;
@
text
@d24 1
a24 1
 *	$Header: RCS/transam.c,v 1.7 91/04/28 09:17:03 cimarron Exp Locker: kemnitz $
d30 1
a30 1
 RcsId("$Header: RCS/transam.c,v 1.7 91/04/28 09:17:03 cimarron Exp Locker: kemnitz $");
d47 1
d171 1
a171 1
	TransactionIdStore(transactionId, &cachedTestXid);
d230 1
a230 1
    TransactionIdStore(transactionId, &cachedTestXid);
d249 1
a249 1
	TransactionIdStore(transactionId, &cachedGetCommitTimeXid);
d307 1
a307 1
	TransactionIdStore(transactionId, &cachedGetCommitTimeXid);
@


1.7
log
@Converted IsValid code into macros and added an improved NodeIsType scheme
@
text
@d24 1
a24 1
 *	$Header: RCS/transam.c,v 1.6 91/02/06 18:17:40 cimarron Exp Locker: cimarron $
d30 1
a30 1
 RcsId("$Header: RCS/transam.c,v 1.6 91/02/06 18:17:40 cimarron Exp Locker: cimarron $");
d181 5
@


1.6
log
@preliminary checkin for access method and system cache changes
@
text
@d24 1
a24 1
 *	$Header: RCS/transam.c,v 1.5 90/10/19 17:08:02 mao Exp Locker: cimarron $
d30 1
a30 1
 RcsId("$Header: RCS/transam.c,v 1.5 90/10/19 17:08:02 mao Exp Locker: cimarron $");
d43 1
@


1.5
log
@don't do bootstrap initialization of object ids here anymore
@
text
@d24 1
a24 1
 *	$Header: RCS/transam.c,v 1.4 90/09/25 16:18:26 kemnitz Exp Locker: mao $
d30 1
a30 1
 RcsId("$Header: RCS/transam.c,v 1.4 90/09/25 16:18:26 kemnitz Exp Locker: mao $");
d498 3
a500 3
    logRelation = 	RelationNameOpenHeapRelation(LogRelationName);
    timeRelation = 	RelationNameOpenHeapRelation(TimeRelationName);
    VariableRelation = 	RelationNameOpenHeapRelation(VariableRelationName);
@


1.4
log
@Updating from revision 1.3 to revision 1.5
@
text
@d24 1
a24 1
 *	$Header: RCS/transam.c,v 1.5 90/09/12 17:54:20 cimarron Exp Locker: cimarron $
d30 1
a30 1
 RcsId("$Header: RCS/transam.c,v 1.5 90/09/12 17:54:20 cimarron Exp Locker: cimarron $");
a80 37
 *	note: we reserve the first 32767 object ids for internal use.
 *	oid's less than this are typically used for bootstrapping.
 *	the choice of 32767 is completely arbitrary - I just don't
 *	want us to run out of reserved oids too soon... -cim 9/10/90
 *
 *	of these 32767 reserved oid, oids 1-16383 are reserved for
 *	allocation in the system catalog bootstrap files: lib/catalog/pg_*.h
 *	and id's 16384 through 32767 are used for oids needed at bootstrap
 *	time, before the variable relation is created.  These should not be
 *	used in the catalog bootstrap files!  Once the variable relation is
 *	initialized, the system uses the oid information stored there.
 * ----------------
 */
static oid FirstObjectIdData = 32768;
oid *FirstObjectId = &FirstObjectIdData;

static oid NextBootstrapObjectIdData = 16384;
oid *NextBootstrapObjectId = &NextBootstrapObjectIdData;

/* --------------------------------
 *	GetNextBootstrapObjectIdBlock
 *
 *	This returns a block of oid's to be allocated during bootstrap
 *	time.  Once the variable relation is initialized, this should
 *	not be called.
 * --------------------------------
 */
void
GetNextBootstrapObjectIdBlock(oid_return, oid_block_size)
    oid *oid_return;
    int oid_block_size;
{
    (*oid_return) = NextBootstrapObjectIdData;
    NextBootstrapObjectIdData += oid_block_size;
}

/* ----------------
d506 2
a507 2
     *   transaction id to FirstTransactionId (id 514).  We also set
     *   initialize the FirstObjectId (oid 32768)
a528 1
	VariableRelationPutNextOid(FirstObjectId);
@


1.3
log
@Initialized "fail" variables to false to
deal with "ghost relations" problem
@
text
@d24 1
a24 1
 *	$Header: RCS/transam.c,v 1.2 90/03/26 20:34:01 cimarron Exp Locker: cimarron $
d28 1
a28 2
#include "transam.h"
 RcsId("$Header: RCS/transam.c,v 1.2 90/03/26 20:34:01 cimarron Exp Locker: cimarron $");
d30 17
d68 50
d543 2
a544 1
     *   transaction id to FirstTransactionId (id 514).
d566 1
@


1.2
log
@*** empty log message ***
@
text
@d24 1
a24 1
 *	$Header: RCS/transam.c,v 1.1 90/03/22 13:02:29 cimarron Exp $
d29 1
a29 1
 RcsId("$Header: RCS/transam.c,v 1.1 90/03/22 13:02:29 cimarron Exp $");
d106 1
a106 1
    bool		fail;      	/* success/failure */
d163 1
a163 1
    bool		fail;      	/* success/failure */
d237 1
a237 1
    bool		fail;      	/* success/failure */
d440 1
a440 1
    bool	  fail;
@


1.1
log
@Initial revision
@
text
@d24 1
a24 1
 *	$Header$
d29 1
a29 1
 RcsId("$Header$");
d43 9
d63 1
a63 1
bool RecoveryCheckingEnableState = false;
d102 1
a102 1
    TransactionStatus 	status;		/* transaction status */
d104 1
a104 1
    ItemPointerData	xptr;		/* item pointer to TransTuple */
d117 10
d128 3
a130 1
     *  page containing our transaction id.
d133 5
a137 2
    TransComputeItemPointer(transactionId, &xptr);
    xidstatus = TransItemPointerGetXidStatus(LogRelation, &xptr, &fail);
d139 3
a141 1
    if (! fail)
d144 2
a145 1

d147 1
a147 1
     *	  here the block didn't contain the tuple we wanted
d160 1
a160 1
    TransactionStatus 	status;		/* new trans status */
d162 1
a162 3
    ItemPointerData  	xptr;		/* item pointer to TransTuple */
    ItemId	   	itemId;		/* item id referencing TransTuple */
    Item		ttitem;		/* TransTuple containing xid status */
d174 1
a174 1
     *    get the transaction commit time
d178 1
a178 1
    
d180 1
a180 1
     *    update the log relation
d183 3
a185 3
    TransComputeItemPointer(LogRelation, transactionId, &xptr);
    TransItemPointerSetXidStatus(LogRelation,
				 &xptr,
d189 7
d203 12
a214 6
	TransComputeItemPointer(TimeRelation, transactionId, &xptr);
	TransItemPointerSetTransactionCommitTime(TimeRelation,
						 &xptr,
						 transactionId,
						 currentTime,
						 &fail);
d216 1
a216 1
    
d226 53
a278 1
/* ----------------------------------------------------------------
d439 1
d475 1
a475 1
     *	 relation by committing the AmiTransactionId (id 1) and we
d477 1
a477 1
     *   transaction id to FirstTransactionId (id 2).
d483 4
a486 3
	 *   XXX transaction log update requires that LogRelation be
	 *       valid so we temporarily set it so we can initialize
	 *	 things properly.  This could be done cleaner.
d491 8
a498 3
	
	TransactionLogUpdate(&AmiTransactionId, XID_COMMIT);
	VariableRelationSetNextXid(&FirstTransactionId);
@
