head	1.18;
access;
symbols
	Version_2_1:1.7
	old_buffer_manager:1.5;
locks; strict;
comment	@ * @;


1.18
date	92.05.28.20.20.52;	author mer;	state Exp;
branches;
next	1.17;

1.17
date	92.04.13.18.54.34;	author mer;	state Exp;
branches;
next	1.16;

1.16
date	92.04.06.18.11.54;	author hong;	state Exp;
branches;
next	1.15;

1.15
date	92.03.05.00.38.06;	author hong;	state Exp;
branches;
next	1.14;

1.14
date	91.11.08.15.42.36;	author kemnitz;	state Exp;
branches;
next	1.13;

1.13
date	91.09.18.18.18.57;	author mer;	state Exp;
branches;
next	1.12;

1.12
date	91.09.05.23.27.40;	author hong;	state Exp;
branches;
next	1.11;

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

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

1.9
date	91.08.14.12.40.34;	author mer;	state Exp;
branches;
next	1.8;

1.8
date	91.08.06.12.23.04;	author mer;	state Exp;
branches;
next	1.7;

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

1.6
date	91.01.18.21.21.24;	author hong;	state Exp;
branches;
next	1.5;

1.5
date	90.11.12.08.08.46;	author hong;	state Exp;
branches;
next	1.4;

1.4
date	90.10.19.17.08.28;	author mao;	state Exp;
branches;
next	1.3;

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

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

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


desc
@new improved transaction access methods support
@


1.18
log
@Transaction ids are now longs and command ids are now shorts
@
text
@/* ----------------------------------------------------------------
 *   FILE
 *	varsup.c
 *	
 *   DESCRIPTION
 *	postgres variable relation support routines
 *
 *   INTERFACE ROUTINES
 *	VariableRelationGetNextXid
 *	VariableRelationPutNextXid
 *	VariableRelationGetLastXid
 *	VariableRelationPutLastXid
 *	GetNewTransactionId
 *	UpdateLastCommittedXid
 *   	
 *   NOTES
 *	presently debugging new routines for oid generation...
 *
 *	VariableRelationGetNextOid
 *	VariableRelationPutNextOid
 *	GetNewObjectIdBlock
 *	GetNewObjectId
 *
 *   IDENTIFICATION
 *	$Header: /private/mer/pg.latest/src/access/transam/RCS/varsup.c,v 1.17 1992/04/13 18:54:34 mer Exp mer $
 * ----------------------------------------------------------------
 */

#include <math.h>

#include "tmp/postgres.h"

 RcsId("$Header: /private/mer/pg.latest/src/access/transam/RCS/varsup.c,v 1.17 1992/04/13 18:54:34 mer Exp mer $");

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

#include "storage/buf.h"
#include "storage/bufmgr.h"
#include "storage/ipc.h"	/* for OIDGENLOCKID */

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

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

#include "catalog/catname.h"

/* ----------
 *      note: we reserve the first 16384 object ids for internal use.
 *      oid's less than this appear in the .bki files.  the choice of
 *      16384 is completely arbitrary.
 * ----------
 */
#define BootstrapObjectIdData 16384

/* ---------------------
 *	spin lock for oid generation
 * ---------------------
 */
int OidGenLockId;

/* ----------------------------------------------------------------
 *	      variable relation query/update routines
 * ----------------------------------------------------------------
 */

/* --------------------------------
 *	VariableRelationGetNextXid
 * --------------------------------
 */
void
VariableRelationGetNextXid(xidP)
    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 nextXid 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->nextXidData, xidP);
    ReleaseBuffer(buf);
}

/* --------------------------------
 *	VariableRelationGetLastXid
 * --------------------------------
 */
void
VariableRelationGetLastXid(xidP)
    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
 * --------------------------------
 */
void
VariableRelationPutNextXid(xid)
    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 nextXid field and
     *  write the page back out to disk.
     * ----------------
     */
    buf = ReadBuffer(VariableRelation, 0);

    if (! BufferIsValid(buf))
    {
	SpinRelease(OidGenLockId);
	elog(WARN, "VariableRelationPutNextXid: ReadBuffer failed");
    }

    var = (VariableRelationContents) BufferGetBlock(buf);

    TransactionIdStore(xid, &(var->nextXidData));

    WriteBuffer(buf);
}

/* --------------------------------
 *	VariableRelationPutLastXid
 * --------------------------------
 */
void
VariableRelationPutLastXid(xid)
    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
 * --------------------------------
 */
void
VariableRelationGetNextOid(oid_return)
    oid *oid_return;
{
    Buffer buf;
    VariableRelationContents var;
    
    /* ----------------
     * We assume that a spinlock has been acquire to guarantee
     * exclusive access to the variable relation.
     * ----------------
     */

    /* ----------------
     *	if the variable relation is not initialized, then we
     *  assume we are running at bootstrap time and so we return
     *  an invalid object id -- during this time GetNextBootstrapObjectId
     *  should be called instead..
     * ----------------
     */
    if (! RelationIsValid(VariableRelation)) {
	if (PointerIsValid(oid_return))
	    (*oid_return) = InvalidObjectId;
	return;
    }
    
    /* ----------------
     *	read the variable page, get the the nextOid field and
     *  release the buffer
     * ----------------
     */
    buf = ReadBuffer(VariableRelation, 0);

    if (! BufferIsValid(buf))
    {
	SpinRelease(OidGenLockId);
	elog(WARN, "VariableRelationGetNextXid: ReadBuffer failed");
    }

    var = (VariableRelationContents) BufferGetBlock(buf);

    if (PointerIsValid(oid_return)) {

        /* ----------------
         * nothing up my sleeve...  what's going on here is that this code
	 * is guaranteed never to be called until all files in data/base/
	 * are created, and the template database exists.  at that point,
	 * we want to append a pg_database tuple.  the first time we do
	 * this, the oid stored in pg_variable will be bogus, so we use
	 * a bootstrap value defined at the top of this file.
	 *
	 * this comment no longer holds true.  This code is called before
	 * all of the files in data/base are created and you can't rely
	 * on system oid's to be less than BootstrapObjectIdData. mer 9/18/91
         * ----------------
         */
	if (ObjectIdIsValid(var->nextOid))
	    (*oid_return) = var->nextOid;
	else
	    (*oid_return) = BootstrapObjectIdData;
    }

    ReleaseBuffer(buf);
}

/* --------------------------------
 *	VariableRelationPutNextOid
 * --------------------------------
 */
void
VariableRelationPutNextOid(oidP)
    oid *oidP;
{
    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;

    /* ----------------
     *	sanity check
     * ----------------
     */
    if (! PointerIsValid(oidP))
    {
	SpinRelease(OidGenLockId);
	elog(WARN, "VariableRelationPutNextOid: invalid oid pointer");
    }
    
    /* ----------------
     *	read the variable page, update the nextXid field and
     *  write the page back out to disk.
     * ----------------
     */
    buf = ReadBuffer(VariableRelation, 0);

    if (! BufferIsValid(buf))
    {
	SpinRelease(OidGenLockId);
	elog(WARN, "VariableRelationPutNextXid: ReadBuffer failed");
    }

    var = (VariableRelationContents) BufferGetBlock(buf);

    var->nextOid = (*oidP);

    WriteBuffer(buf);
}

/* ----------------------------------------------------------------
 *		transaction id generation support
 * ----------------------------------------------------------------
 */

/* ----------------
 *	GetNewTransactionId
 *
 *	In the version 2 transaction system, transaction id's are
 *	restricted in several ways.
 *
 *	First, all transaction id's are even numbers (4, 88, 121342, etc).
 *	This means the binary representation of the number will never
 *	have the least significent bit set.  This bit is reserved to
 *	indicate that the transaction id does not in fact hold an XID,
 *	but rather a commit time.  This makes it possible for the
 *	vaccuum daemon to disgard information from the log and time
 *	relations for committed tuples.  This is important when archiving
 *	tuples to an optical disk because tuples with commit times
 *	stored in their xid fields will not need to consult the log
 *	and time relations.
 *
 *	Second, since we may someday preform compression of the data
 *	in the log and time relations, we cause the numbering of the
 *	transaction ids to begin at 512.  This means that some space
 *	on the page of the log and time relations corresponding to
 *	transaction id's 0 - 510 will never be used.  This space is
 *	in fact used to store the version number of the postgres
 *	transaction log and will someday store compression information
 *	about the log.
 *
 *	Lastly, rather then access the variable relation each time
 *	a backend requests a new transction id, we "prefetch" 32
 *	transaction id's by incrementing the nextXid stored in the
 *	var relation by 64 (remember only even xid's are legal) and then
 *	returning these id's one at a time until they are exhausted.
 *  	This means we reduce the number of accesses to the variable
 *	relation by 32 for each backend.
 *
 *  	Note:  32 has no special significance.  We don't want the
 *	       number to be too large because if when the backend
 *	       terminates, we lose the xid's we cached.
 *
 * ----------------
 */

#define VAR_XID_PREFETCH	32

static int prefetched_xid_count = 0;
TransactionId next_prefetched_xid;

void
GetNewTransactionId(xid)
    TransactionId *xid;
{
    TransactionId nextid;

    /* ----------------
     *	during bootstrap initialization, we return the special
     *  bootstrap transaction id.
     * ----------------
     */
    if (AMI_OVERRIDE) {	
	TransactionIdStore(AmiTransactionId, xid);
	return;
    }
 
    /* ----------------
     *  if we run out of prefetched xids, then we get some
     *  more before handing them out to the caller.
     * ----------------
     */
    
    if (prefetched_xid_count == 0) {
	/* ----------------
	 *	obtain exclusive access to the variable relation page
	 *
	 *	get the "next" xid from the variable relation
	 *	and save it in the prefetched id.
	 * ----------------
	 */
	SpinAcquire(OidGenLockId);
	VariableRelationGetNextXid(&nextid);
	TransactionIdStore(nextid, &next_prefetched_xid);
	
	/* ----------------
	 *	now increment the variable relation's next xid
	 *	and reset the prefetched_xid_count.  We multiply
	 *	the id by two because our xid's are always even.
	 * ----------------
	 */
	prefetched_xid_count = VAR_XID_PREFETCH;
	TransactionIdAdd(&nextid, prefetched_xid_count);
	VariableRelationPutNextXid(nextid);
	SpinRelease(OidGenLockId);
    }
    
    /* ----------------
     *	return the next prefetched xid in the pointer passed by
     *  the user and decrement the prefetch count.  We add two
     *  to id we return the next time this is called because our
     *	transaction ids are always even.
     *
     *  XXX Transaction Ids used to be even as the low order bit was
     *      used to determine commit status.  This is no long true so
     *      we now use even and odd transaction ids. -mer 5/26/92
     * ----------------
     */
    TransactionIdStore(next_prefetched_xid, xid);
    TransactionIdAdd(&next_prefetched_xid, 1);
    prefetched_xid_count--;
}

/* ----------------
 *	UpdateLastCommittedXid
 * ----------------
 */

void
UpdateLastCommittedXid(xid)
    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
 * ----------------------------------------------------------------
 */

/* ----------------
 *	GetNewObjectIdBlock
 *
 *	This support function is used to allocate a block of object ids
 *	of the given size.  applications wishing to do their own object
 *	id assignments should use this 
 * ----------------
 */

void
GetNewObjectIdBlock(oid_return, oid_block_size)
    oid *oid_return;		/* place to return the new object id */
    int oid_block_size;		/* number of oids desired */
{
    oid nextoid;		

    /* ----------------
     *	SOMEDAY obtain exclusive access to the variable relation page
     *  That someday is today -mer 6 Aug 1992
     * ----------------
     */
    SpinAcquire(OidGenLockId);
	
    /* ----------------
     *	get the "next" oid from the variable relation
     *	and give it to the caller.
     * ----------------
     */
    VariableRelationGetNextOid(&nextoid);
    if (PointerIsValid(oid_return))
	(*oid_return) = nextoid;
    
    /* ----------------
     *	now increment the variable relation's next oid
     *	field by the size of the oid block requested.
     * ----------------
     */
    nextoid += oid_block_size;
    VariableRelationPutNextOid(&nextoid);
	
    /* ----------------
     *	SOMEDAY relinquish our lock on the variable relation page
     *  That someday is today -mer 6 Apr 1992
     * ----------------
     */
    SpinRelease(OidGenLockId);
}

/* ----------------
 *	GetNewObjectId
 *
 *	This function allocates and parses out object ids.  Like
 *	GetNewTransactionId(), it "prefetches" 32 object ids by
 *	incrementing the nextOid stored in the var relation by 32 and then
 *	returning these id's one at a time until they are exhausted.
 *  	This means we reduce the number of accesses to the variable
 *	relation by 32 for each backend.
 *
 *  	Note:  32 has no special significance.  We don't want the
 *	       number to be too large because if when the backend
 *	       terminates, we lose the oids we cached.
 *
 * ----------------
 */

#define VAR_OID_PREFETCH	32

int prefetched_oid_count = 0;
oid next_prefetched_oid;

void
GetNewObjectId(oid_return)
    oid *oid_return;		/* place to return the new object id */
{
    /* ----------------
     *  if we run out of prefetched oids, then we get some
     *  more before handing them out to the caller.
     * ----------------
     */
    
    if (prefetched_oid_count == 0) {
	int oid_block_size = VAR_OID_PREFETCH;

	/* ----------------
	 *	during bootstrap time, we want to allocate oids
	 *	one at a time.  Otherwise there might be some
	 *      bootstrap oid's left in the block we prefetch which
	 *	would be passed out after the variable relation was
	 *	initialized.  This would be bad.
	 * ----------------
	 */
	if (! RelationIsValid(VariableRelation))
	    VariableRelation = heap_openr(VariableRelationName);
	
	/* ----------------
	 *	get a new block of prefetched object ids.
	 * ----------------
	 */
	GetNewObjectIdBlock(&next_prefetched_oid, oid_block_size);

	/* ----------------
	 *	now reset the prefetched_oid_count.
	 * ----------------
	 */
	prefetched_oid_count = oid_block_size;
    }
    
    /* ----------------
     *	return the next prefetched oid in the pointer passed by
     *  the user and decrement the prefetch count.
     * ----------------
     */
    if (PointerIsValid(oid_return))
	(*oid_return) = next_prefetched_oid;
    
    next_prefetched_oid++;
    prefetched_oid_count--;
}
@


1.17
log
@fun with spinlocks, fix up protection for variable relation
@
text
@d25 1
a25 1
 *	$Header: /u/mer/pg/src/access/transam/RCS/varsup.c,v 1.16 1992/04/06 18:11:54 hong Exp mer $
d33 1
a33 1
 RcsId("$Header: /u/mer/pg/src/access/transam/RCS/varsup.c,v 1.16 1992/04/06 18:11:54 hong Exp mer $");
d73 2
a74 2
VariableRelationGetNextXid(xid)
    TransactionId xid;
d107 1
a107 1
    TransactionIdStore(&(var->nextXidData), (Pointer) xid);
d116 2
a117 2
VariableRelationGetLastXid(xid)
    TransactionId xid;
d150 1
a150 1
    TransactionIdStore(&(var->lastXidData), (Pointer) xid);
d194 1
a194 1
    TransactionIdStore(xid, (Pointer) &(var->nextXidData));
d238 1
a238 1
    TransactionIdStore(xid, (Pointer) &(var->lastXidData));
d415 1
a415 1
TransactionIdData next_prefetched_xid;
d419 1
a419 1
    TransactionId xid;
d421 1
a421 1
    TransactionIdData nextid;
d429 1
a429 1
	TransactionIdStore(AmiTransactionId, (Pointer) xid);
d449 1
a449 1
	TransactionIdStore(&nextid, (Pointer) &next_prefetched_xid);
d458 2
a459 2
	TransactionIdAdd(&nextid, prefetched_xid_count * 2);
	VariableRelationPutNextXid(&nextid);
d468 4
d474 2
a475 2
    TransactionIdStore(&next_prefetched_xid, (Pointer) xid);
    TransactionIdAdd(&next_prefetched_xid, 2);
d488 1
a488 1
    TransactionIdData lastid;
d508 1
a508 1
    if (TransactionIdIsLessThan(&lastid, xid))
@


1.16
log
@do spin lock when allocating transaction ids to fix a multiuser bug
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.15 92/03/05 00:38:06 hong Exp Locker: mer $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.15 92/03/05 00:38:06 hong Exp Locker: mer $");
d61 1
a61 1
static int OidGenLockId = OIDGENLOCKID;
d80 6
a91 1
    RelationSetLockForRead(VariableRelation);
d100 2
d103 1
a106 2
    RelationUnsetLockForRead(VariableRelation);

d123 6
d143 2
d146 1
d167 6
a178 2
    RelationSetLockForWrite(VariableRelation);

d187 2
d190 1
a196 2

    RelationUnsetLockForWrite(VariableRelation);
d211 6
d231 2
d234 1
d255 6
d281 2
d284 1
d324 6
d341 2
d344 1
d354 2
d357 1
d414 1
a414 1
int prefetched_xid_count = 0;
d442 1
a442 4
	 * ----------------
	 */
	
	/* ----------------
a460 5
	
	/* ----------------
	 *	relinquish our lock on the variable relation page
	 * ----------------
	 */
d486 3
a488 9
    /* ----------------
     *	SOMEDAY obtain exclusive access to the variable relation
     *  That someday is today -mer 5 Aug 1991
     *
     *  Bootstrapping is the only time when VariableRelation won't
     *  initialized, and the lock manager should be turned off at that
     *  time anyway, but right now it isn't.  To be safe now and in the 
     *  future I have put in the check.
     * ----------------
a489 2
    if (RelationIsValid(VariableRelation))
        RelationSetLockForRead(VariableRelation);
a506 7
    /* ----------------
     *	SOMEDAY relinquish our lock on the variable relation page
     *  That someday is today -mer 5 Aug 1991
     * ----------------
     */
    if (RelationIsValid(VariableRelation))
        RelationUnsetLockForRead(VariableRelation);
d532 1
a532 6
     *  That someday is today -mer 5 Aug 1991
     *
     *  Bootstrapping is the only time when VariableRelation won't
     *  initialized, and the lock manager should be turned off at that
     *  time anyway, but right now it isn't.  To be safe now and in the 
     *  future I have put in the check.
a534 2
    if (RelationIsValid(VariableRelation))
        RelationSetLockForRead(VariableRelation);
d556 1
a556 1
     *  That someday is today -mer 5 Aug 1991
a559 2
    if (RelationIsValid(VariableRelation))
        RelationUnsetLockForRead(VariableRelation);
@


1.15
log
@cleaning up and whacking out buffer leaks
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.14 91/11/08 15:42:36 kemnitz Exp $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.14 91/11/08 15:42:36 kemnitz Exp $");
a38 1
#ifdef sequent
a39 1
#endif
d57 6
d400 1
d413 1
a494 3
#ifdef sequent
static int OidGenLockId = OIDGENLOCKID;
#endif
d515 1
a515 3
#ifdef sequent
    ExclusiveLock(OidGenLockId);
#endif
d539 1
a539 3
#ifdef sequent
    ExclusiveUnlock(OidGenLockId);
#endif
@


1.14
log
@fixed prototypes
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.13 91/09/18 18:18:57 mer Exp Locker: kemnitz $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.13 91/09/18 18:18:57 mer Exp Locker: kemnitz $");
d91 1
a91 1
	elog(WARN, "VariableRelationGetNextXid: RelationGetBuffer failed");
d127 1
a127 1
	elog(WARN, "VariableRelationGetNextXid: RelationGetBuffer failed");
d164 1
a164 1
	elog(WARN, "VariableRelationPutNextXid: RelationGetBuffer failed");
d201 1
a201 1
	elog(WARN, "VariableRelationPutLastXid: RelationGetBuffer failed");
d242 1
a242 1
	elog(WARN, "VariableRelationGetNextXid: RelationGetBuffer failed");
d303 1
a303 1
	elog(WARN, "VariableRelationPutNextXid: RelationGetBuffer failed");
@


1.13
log
@purge IsSystemRelation() from the code
@
text
@d25 1
a25 1
 *	$Header: /users/mer/postgres/src/access/transam/RCS/varsup.c,v 1.12 1991/09/05 23:27:40 hong Exp mer $
d33 1
a33 1
 RcsId("$Header: /users/mer/postgres/src/access/transam/RCS/varsup.c,v 1.12 1991/09/05 23:27:40 hong Exp mer $");
d97 1
a97 1
    TransactionIdStore(&(var->nextXidData), xid);
d131 1
a131 1
    TransactionIdStore(&(var->lastXidData), xid);
d168 1
a168 1
    TransactionIdStore(xid, &(var->nextXidData));
d205 1
a205 1
    TransactionIdStore(xid, &(var->lastXidData));
d375 1
a375 1
	TransactionIdStore(AmiTransactionId, xid);
d397 1
a397 1
	TransactionIdStore(&nextid, &next_prefetched_xid);
d422 1
a422 1
    TransactionIdStore(&next_prefetched_xid, xid);
@


1.12
log
@fix sequent compilation errors
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.11 91/08/29 23:54:38 mer Exp $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.11 91/08/29 23:54:38 mer Exp $");
d51 8
d255 4
@


1.11
log
@purge old lmgr code
@
text
@d25 1
a25 1
 *	$Header: /users/mer/postgres/src/access/transam/RCS/varsup.c,v 1.10 1991/08/14 22:16:14 mer Exp mer $
d33 1
a33 1
 RcsId("$Header: /users/mer/postgres/src/access/transam/RCS/varsup.c,v 1.10 1991/08/14 22:16:14 mer Exp mer $");
d478 1
a478 1
static SPINLOCK OidGenLockId = OIDGENLOCKID;
d501 1
a501 1
    SpinAcquire(OidGenLockId);
d527 1
a527 1
    SpinRelease(OidGenLockId);
@


1.10
log
@put relation locks around reads/writes to pg_variable
@
text
@d25 1
a25 1
 *	$Header: /users/mer/postgres/src/access/transam/RCS/varsup.c,v 1.9 91/08/14 12:40:34 mer Exp Locker: mer $
d33 1
a33 1
 RcsId("$Header: /users/mer/postgres/src/access/transam/RCS/varsup.c,v 1.9 91/08/14 12:40:34 mer Exp Locker: mer $");
a39 1
#include "storage/pladt.h"	/* for LockId */
d478 1
a478 1
static LockId OidGenLockId = OIDGENLOCKID;
d501 1
a501 1
    ExclusiveLock(OidGenLockId);
d527 1
a527 1
    ExclusiveUnlock(OidGenLockId);
@


1.9
log
@make static oid BootstrapObjectIdData a defined constant in postgres.h
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.8 91/08/06 12:23:04 mer Exp Locker: mer $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.8 91/08/06 12:23:04 mer Exp Locker: mer $");
d75 1
d88 2
a90 1

d147 2
d164 2
@


1.8
log
@add synchronization in dealing with system catalogs
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.7 91/02/06 18:17:47 cimarron Exp Locker: mer $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.7 91/02/06 18:17:47 cimarron Exp Locker: mer $");
a50 8

/* ----------
 *	note: we reserve the first 16384 object ids for internal use.
 *	oid's less than this appear in the .bki files.  the choice of
 *	16384 is completely arbitrary.
 * ----------
 */
static oid BootstrapObjectIdData = 16384;
@


1.7
log
@preliminary checkin for access method and system cache changes
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.6 91/01/18 21:21:24 hong Exp Locker: cimarron $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.6 91/01/18 21:21:24 hong Exp Locker: cimarron $");
d430 7
a436 1
     *	SOMEDAY obtain exclusive access to the variable relation page
d439 2
d460 1
d463 2
d493 6
d501 2
d526 1
d532 2
@


1.6
log
@for new buffer manager, changed ReadBuffer() interface.
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.5 90/11/12 08:08:46 hong Exp Locker: hong $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.5 90/11/12 08:08:46 hong Exp Locker: hong $");
d558 1
a558 2
	    VariableRelation =
		RelationNameOpenHeapRelation(VariableRelationName);
@


1.5
log
@added locking to oid allocation for parallel backends
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.4 90/10/19 17:08:28 mao Exp $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.4 90/10/19 17:08:28 mao Exp $");
d88 1
a88 1
    buf = ReadBuffer(VariableRelation, 0, 0);
d123 1
a123 1
    buf = ReadBuffer(VariableRelation, 0, 0);
d158 1
a158 1
    buf = ReadBuffer(VariableRelation, 0, 0);
d193 1
a193 1
    buf = ReadBuffer(VariableRelation, 0, 0);
d234 1
a234 1
    buf = ReadBuffer(VariableRelation, 0, 0);
d291 1
a291 1
    buf = ReadBuffer(VariableRelation, 0, 0);
@


1.4
log
@get rid of bootstrap OID initialization.  it turns out we never need
any object ids until pg_variable exists, at which point we can do an
open on it and handle the first fetch for data as a special case.
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.3 90/09/25 16:18:40 kemnitz Exp $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.3 90/09/25 16:18:40 kemnitz Exp $");
d39 4
d469 4
d484 3
d509 3
@


1.3
log
@Updating from revision 1.2 to revision 1.5
@
text
@d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.5 90/09/12 17:54:37 cimarron Exp Locker: cimarron $
d33 1
a33 1
 RcsId("$Header: RCS/varsup.c,v 1.5 90/09/12 17:54:37 cimarron Exp Locker: cimarron $");
d43 1
d46 10
d237 1
a237 2
    if (PointerIsValid(oid_return))
	(*oid_return) = var->nextOid;
d239 15
a472 12
     *	if we are running during bootstrap time, then don't go to the
     *  disk.. instead allocate the block from the set of special oids
     *  reserved for this time..
     * ----------------
     */
    if (! RelationIsValid(VariableRelation)) {
	if (PointerIsValid(oid_return))
	    GetNextBootstrapObjectIdBlock(oid_return, oid_block_size);
	return;
    }

    /* ----------------
d544 2
a545 1
	    oid_block_size = 1;
d552 1
a552 1
	
@


1.2
log
@*** empty log message ***
@
text
@d17 1
a17 2
 *	Read the notes on the transaction system in the comments
 *	above GetNewTransactionId.
d19 5
d25 1
a25 1
 *	$Header: RCS/varsup.c,v 1.1 90/03/22 13:02:58 cimarron Exp $
d29 1
a29 2
#include "transam.h"
 RcsId("$Header: RCS/varsup.c,v 1.1 90/03/22 13:02:58 cimarron Exp $");
d31 14
d190 90
a279 1
/* ----------------
d320 1
a320 1
#define VAR_PREFETCH	32
d323 1
a323 1
TransactionIdData next_prefetched_id;
d359 1
a359 1
	TransactionIdStore(&nextid, &next_prefetched_id);
d367 1
a367 1
	prefetched_xid_count = VAR_PREFETCH;
d384 2
a385 2
    TransactionIdStore(&next_prefetched_id, xid);
    TransactionIdAdd(&next_prefetched_id, 2);
d401 1
a401 1
     *	obtain exclusive access to the variable relation page
d419 1
a419 1
	VariableRelationPutNextXid(xid);
d422 1
a422 1
     *	relinquish our lock on the variable relation page
d427 130
@


1.1
log
@Initial revision
@
text
@d11 1
d17 3
a19 1
 *	
d21 1
a21 1
 *	$Header$
d26 1
a26 1
 RcsId("$Header$");
d175 36
d214 2
d236 2
a237 10
     *	here we "prefetch" 16 transaction id's by incrementing the
     *  nextXid stored in the var relation by 16 and then returning
     *  these id's one at a time until they are exhausted.
     *
     *  This means we reduce the number of times we access the var
     *  relation's page by 16.
     *
     *  Note:  16 has no special significance.  We don't want the
     *	       number to be too large because if the system crashes
     *	       we lose the xid's we prefetched.
d248 1
a248 1
	 *	get the next xid from the variable relation
d254 1
a254 1

d257 2
a258 1
	 *	and reset the prefetched_xid_count
d261 2
a262 2
	prefetched_xid_count = 16;
	TransactionIdAdd(&nextid, prefetched_xid_count);
d270 1
a270 1

d273 3
a275 1
     *  the user and decrement the prefetch count.
d279 1
a279 1
    TransactionIdIncrement(&next_prefetched_id);
d313 1
a313 1
	VariableRelationPutLextXid(xid);
@
