mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
No more #ifdef XLOG.
This commit is contained in:
@@ -27,4 +27,3 @@ RmgrData RmgrTable[] = {
|
||||
{"Gist", gist_redo, gist_undo, gist_desc},
|
||||
{"Sequence", seq_redo, seq_undo, seq_desc}
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.37 2000/11/21 21:15:57 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.38 2000/11/30 08:46:22 vadim Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This file contains the high level access-method interface to the
|
||||
@@ -424,23 +424,12 @@ InitializeTransactionLog(void)
|
||||
SpinAcquire(OidGenLockId);
|
||||
if (!TransactionIdDidCommit(AmiTransactionId))
|
||||
{
|
||||
|
||||
/* ----------------
|
||||
* SOMEDAY initialize the information stored in
|
||||
* the headers of the log/variable relations.
|
||||
* ----------------
|
||||
*/
|
||||
TransactionLogUpdate(AmiTransactionId, XID_COMMIT);
|
||||
TransactionIdStore(AmiTransactionId, &cachedTestXid);
|
||||
cachedTestXidStatus = XID_COMMIT;
|
||||
#ifdef XLOG
|
||||
Assert(!IsUnderPostmaster &&
|
||||
ShmemVariableCache->nextXid <= FirstTransactionId);
|
||||
ShmemVariableCache->nextXid = FirstTransactionId;
|
||||
#else
|
||||
VariableRelationPutNextXid(FirstTransactionId);
|
||||
#endif
|
||||
|
||||
}
|
||||
else if (RecoveryCheckingEnabled())
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.26 2000/10/28 16:20:53 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.27 2000/11/30 08:46:22 vadim Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This file contains support functions for the high
|
||||
@@ -186,9 +186,7 @@ TransBlockGetXidStatus(Block tblock,
|
||||
bits8 bit2;
|
||||
BitIndex offset;
|
||||
|
||||
#ifdef XLOG
|
||||
tblock = (Block) ((char*) tblock + sizeof(XLogRecPtr));
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* calculate the index into the transaction data where
|
||||
@@ -231,9 +229,7 @@ TransBlockSetXidStatus(Block tblock,
|
||||
Index index;
|
||||
BitIndex offset;
|
||||
|
||||
#ifdef XLOG
|
||||
tblock = (Block) ((char*) tblock + sizeof(XLogRecPtr));
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* calculate the index into the transaction data where
|
||||
|
||||
@@ -1,290 +1,51 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* varsup.c
|
||||
* postgres variable relation support routines
|
||||
*
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
* postgres OID & XID variables support routines
|
||||
*
|
||||
* Copyright (c) 2000, PostgreSQL, Inc
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.33 2000/11/20 16:47:30 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.34 2000/11/30 08:46:22 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#ifdef XLOG
|
||||
#include "xlog_varsup.c"
|
||||
#else
|
||||
|
||||
#include "access/heapam.h"
|
||||
#include "catalog/catname.h"
|
||||
#include "access/transam.h"
|
||||
#include "storage/proc.h"
|
||||
|
||||
static void GetNewObjectIdBlock(Oid *oid_return, int oid_block_size);
|
||||
static void VariableRelationGetNextOid(Oid *oid_return);
|
||||
static void VariableRelationGetNextXid(TransactionId *xidP);
|
||||
static void VariableRelationPutNextOid(Oid oid);
|
||||
SPINLOCK OidGenLockId;
|
||||
|
||||
/* ---------------------
|
||||
* spin lock for oid generation
|
||||
* ---------------------
|
||||
*/
|
||||
int OidGenLockId;
|
||||
extern SPINLOCK XidGenLockId;
|
||||
extern void XLogPutNextOid(Oid nextOid);
|
||||
|
||||
/* ---------------------
|
||||
* pointer to "variable cache" in shared memory (set up by shmem.c)
|
||||
* ---------------------
|
||||
*/
|
||||
/* pointer to "variable cache" in shared memory (set up by shmem.c) */
|
||||
VariableCache ShmemVariableCache = NULL;
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* variable relation query/update routines
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* --------------------------------
|
||||
* VariableRelationGetNextXid
|
||||
* --------------------------------
|
||||
*/
|
||||
static void
|
||||
VariableRelationGetNextXid(TransactionId *xidP)
|
||||
{
|
||||
Buffer buf;
|
||||
VariableRelationContents var;
|
||||
|
||||
/* ----------------
|
||||
* We assume that a spinlock has been acquired 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(ERROR, "VariableRelationGetNextXid: ReadBuffer failed");
|
||||
}
|
||||
|
||||
var = (VariableRelationContents) BufferGetBlock(buf);
|
||||
|
||||
TransactionIdStore(var->nextXidData, xidP);
|
||||
|
||||
ReleaseBuffer(buf);
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
* VariableRelationPutNextXid
|
||||
* --------------------------------
|
||||
*/
|
||||
void
|
||||
VariableRelationPutNextXid(TransactionId xid)
|
||||
{
|
||||
Buffer buf;
|
||||
VariableRelationContents var;
|
||||
|
||||
/* ----------------
|
||||
* We assume that a spinlock has been acquired 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 (with immediate write).
|
||||
* ----------------
|
||||
*/
|
||||
buf = ReadBuffer(VariableRelation, 0);
|
||||
|
||||
if (!BufferIsValid(buf))
|
||||
{
|
||||
SpinRelease(OidGenLockId);
|
||||
elog(ERROR, "VariableRelationPutNextXid: ReadBuffer failed");
|
||||
}
|
||||
|
||||
var = (VariableRelationContents) BufferGetBlock(buf);
|
||||
|
||||
TransactionIdStore(xid, &(var->nextXidData));
|
||||
|
||||
FlushBuffer(buf, true, true);
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
* VariableRelationGetNextOid
|
||||
* --------------------------------
|
||||
*/
|
||||
static void
|
||||
VariableRelationGetNextOid(Oid *oid_return)
|
||||
{
|
||||
Buffer buf;
|
||||
VariableRelationContents var;
|
||||
|
||||
/* ----------------
|
||||
* We assume that a spinlock has been acquired 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 (this path should never be taken, probably).
|
||||
* ----------------
|
||||
*/
|
||||
if (!RelationIsValid(VariableRelation))
|
||||
{
|
||||
(*oid_return) = InvalidOid;
|
||||
return;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* read the variable page, get the the nextOid field and
|
||||
* release the buffer
|
||||
* ----------------
|
||||
*/
|
||||
buf = ReadBuffer(VariableRelation, 0);
|
||||
|
||||
if (!BufferIsValid(buf))
|
||||
{
|
||||
SpinRelease(OidGenLockId);
|
||||
elog(ERROR, "VariableRelationGetNextOid: ReadBuffer failed");
|
||||
}
|
||||
|
||||
var = (VariableRelationContents) BufferGetBlock(buf);
|
||||
|
||||
(*oid_return) = var->nextOid;
|
||||
|
||||
ReleaseBuffer(buf);
|
||||
}
|
||||
|
||||
/* --------------------------------
|
||||
* VariableRelationPutNextOid
|
||||
* --------------------------------
|
||||
*/
|
||||
static void
|
||||
VariableRelationPutNextOid(Oid oid)
|
||||
{
|
||||
Buffer buf;
|
||||
VariableRelationContents var;
|
||||
|
||||
/* ----------------
|
||||
* We assume that a spinlock has been acquired 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(ERROR, "VariableRelationPutNextOid: ReadBuffer failed");
|
||||
}
|
||||
|
||||
var = (VariableRelationContents) BufferGetBlock(buf);
|
||||
|
||||
var->nextOid = oid;
|
||||
|
||||
WriteBuffer(buf);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* transaction id generation support
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* ----------------
|
||||
* GetNewTransactionId
|
||||
*
|
||||
* Transaction IDs are allocated via a cache in shared memory.
|
||||
* Each time we need more IDs, we advance the "next XID" value
|
||||
* in pg_variable by VAR_XID_PREFETCH and set the cache to
|
||||
* show that many XIDs as available. Then, allocating those XIDs
|
||||
* requires just a spinlock and not a buffer read/write cycle.
|
||||
*
|
||||
* Since the cache is shared across all backends, cached but unused
|
||||
* XIDs are not lost when a backend exits, only when the postmaster
|
||||
* quits or forces shared memory reinit. So we can afford to have
|
||||
* a pretty big value of VAR_XID_PREFETCH.
|
||||
*
|
||||
* This code does not worry about initializing the transaction counter
|
||||
* (see transam.c's InitializeTransactionLog() for that). We also
|
||||
* ignore the possibility that the counter could someday wrap around.
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
#define VAR_XID_PREFETCH 1024
|
||||
|
||||
void
|
||||
GetNewTransactionId(TransactionId *xid)
|
||||
{
|
||||
|
||||
/* ----------------
|
||||
* during bootstrap initialization, we return the special
|
||||
* bootstrap transaction id.
|
||||
* ----------------
|
||||
/*
|
||||
* During bootstrap initialization, we return the special
|
||||
* bootstrap transaction id.
|
||||
*/
|
||||
if (AMI_OVERRIDE)
|
||||
{
|
||||
TransactionIdStore(AmiTransactionId, xid);
|
||||
*xid = AmiTransactionId;
|
||||
return;
|
||||
}
|
||||
|
||||
SpinAcquire(OidGenLockId); /* not good for concurrency... */
|
||||
|
||||
if (ShmemVariableCache->xid_count == 0)
|
||||
{
|
||||
TransactionId nextid;
|
||||
|
||||
VariableRelationGetNextXid(&nextid);
|
||||
TransactionIdStore(nextid, &(ShmemVariableCache->nextXid));
|
||||
ShmemVariableCache->xid_count = VAR_XID_PREFETCH;
|
||||
TransactionIdAdd(&nextid, VAR_XID_PREFETCH);
|
||||
VariableRelationPutNextXid(nextid);
|
||||
}
|
||||
|
||||
TransactionIdStore(ShmemVariableCache->nextXid, xid);
|
||||
TransactionIdAdd(&(ShmemVariableCache->nextXid), 1);
|
||||
(ShmemVariableCache->xid_count)--;
|
||||
SpinAcquire(XidGenLockId);
|
||||
*xid = ShmemVariableCache->nextXid;
|
||||
(ShmemVariableCache->nextXid)++;
|
||||
|
||||
if (MyProc != (PROC *) NULL)
|
||||
MyProc->xid = *xid;
|
||||
|
||||
SpinRelease(OidGenLockId);
|
||||
SpinRelease(XidGenLockId);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -294,30 +55,20 @@ void
|
||||
ReadNewTransactionId(TransactionId *xid)
|
||||
{
|
||||
|
||||
/* ----------------
|
||||
* during bootstrap initialization, we return the special
|
||||
* bootstrap transaction id.
|
||||
* ----------------
|
||||
/*
|
||||
* During bootstrap initialization, we return the special
|
||||
* bootstrap transaction id.
|
||||
*/
|
||||
if (AMI_OVERRIDE)
|
||||
{
|
||||
TransactionIdStore(AmiTransactionId, xid);
|
||||
*xid = AmiTransactionId;
|
||||
return;
|
||||
}
|
||||
|
||||
SpinAcquire(OidGenLockId); /* not good for concurrency... */
|
||||
SpinAcquire(XidGenLockId);
|
||||
*xid = ShmemVariableCache->nextXid;
|
||||
SpinRelease(XidGenLockId);
|
||||
|
||||
/*
|
||||
* Note that we don't check is ShmemVariableCache->xid_count equal to
|
||||
* 0 or not. This will work as long as we don't call
|
||||
* ReadNewTransactionId() before GetNewTransactionId().
|
||||
*/
|
||||
if (ShmemVariableCache->nextXid == 0)
|
||||
elog(ERROR, "ReadNewTransactionId: ShmemVariableCache->nextXid is not initialized");
|
||||
|
||||
TransactionIdStore(ShmemVariableCache->nextXid, xid);
|
||||
|
||||
SpinRelease(OidGenLockId);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
@@ -325,199 +76,67 @@ ReadNewTransactionId(TransactionId *xid)
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* ----------------
|
||||
* GetNewObjectIdBlock
|
||||
*
|
||||
* This support function is used to allocate a block of object ids
|
||||
* of the given size.
|
||||
* ----------------
|
||||
*/
|
||||
static void
|
||||
GetNewObjectIdBlock(Oid *oid_return, /* place to return the first new
|
||||
* object id */
|
||||
int oid_block_size) /* number of oids desired */
|
||||
{
|
||||
Oid firstfreeoid;
|
||||
Oid nextoid;
|
||||
|
||||
/* ----------------
|
||||
* Obtain exclusive access to the variable relation page
|
||||
* ----------------
|
||||
*/
|
||||
SpinAcquire(OidGenLockId);
|
||||
|
||||
/* ----------------
|
||||
* get the "next" oid from the variable relation
|
||||
* ----------------
|
||||
*/
|
||||
VariableRelationGetNextOid(&firstfreeoid);
|
||||
|
||||
/* ----------------
|
||||
* Allocate the range of OIDs to be returned to the caller.
|
||||
*
|
||||
* There are two things going on here.
|
||||
*
|
||||
* One: in a virgin database pg_variable will initially contain zeroes,
|
||||
* so we will read out firstfreeoid = InvalidOid. We want to start
|
||||
* allocating OIDs at BootstrapObjectIdData instead (OIDs below that
|
||||
* are reserved for static assignment in the initial catalog data).
|
||||
*
|
||||
* Two: if a database is run long enough, the OID counter will wrap
|
||||
* around. We must not generate an invalid OID when that happens,
|
||||
* and it seems wise not to generate anything in the reserved range.
|
||||
* Therefore we advance to BootstrapObjectIdData in this case too.
|
||||
*
|
||||
* The comparison here assumes that Oid is an unsigned type.
|
||||
*/
|
||||
nextoid = firstfreeoid + oid_block_size;
|
||||
|
||||
if (! OidIsValid(firstfreeoid) || nextoid < firstfreeoid)
|
||||
{
|
||||
/* Initialization or wraparound time, force it up to safe range */
|
||||
firstfreeoid = BootstrapObjectIdData;
|
||||
nextoid = firstfreeoid + oid_block_size;
|
||||
}
|
||||
|
||||
(*oid_return) = firstfreeoid;
|
||||
|
||||
/* ----------------
|
||||
* Update the variable relation to show the block range as used.
|
||||
* ----------------
|
||||
*/
|
||||
VariableRelationPutNextOid(nextoid);
|
||||
|
||||
/* ----------------
|
||||
* Relinquish our lock on the variable relation page
|
||||
* ----------------
|
||||
*/
|
||||
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 when the backend
|
||||
* terminates, we lose the oids we cached.
|
||||
*
|
||||
* Question: couldn't we use a shared-memory cache just like XIDs?
|
||||
* That would allow a larger interval between pg_variable updates
|
||||
* without cache losses. Note, however, that we can assign an OID
|
||||
* without even a spinlock from the backend-local OID cache.
|
||||
* Maybe two levels of caching would be good.
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
#define VAR_OID_PREFETCH 32
|
||||
|
||||
static int prefetched_oid_count = 0;
|
||||
static Oid next_prefetched_oid;
|
||||
#define VAR_OID_PREFETCH 8192
|
||||
static Oid lastSeenOid = InvalidOid;
|
||||
|
||||
void
|
||||
GetNewObjectId(Oid *oid_return) /* place to return the new object id */
|
||||
GetNewObjectId(Oid *oid_return)
|
||||
{
|
||||
/* ----------------
|
||||
* if we run out of prefetched oids, then we get some
|
||||
* more before handing them out to the caller.
|
||||
* ----------------
|
||||
*/
|
||||
SpinAcquire(OidGenLockId);
|
||||
|
||||
if (prefetched_oid_count == 0)
|
||||
/* If we run out of logged for use oids then we log more */
|
||||
if (ShmemVariableCache->oidCount == 0)
|
||||
{
|
||||
int oid_block_size = VAR_OID_PREFETCH;
|
||||
|
||||
/* ----------------
|
||||
* Make sure pg_variable is open.
|
||||
* ----------------
|
||||
*/
|
||||
if (!RelationIsValid(VariableRelation))
|
||||
VariableRelation = heap_openr(VariableRelationName, NoLock);
|
||||
|
||||
/* ----------------
|
||||
* 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;
|
||||
XLogPutNextOid(ShmemVariableCache->nextOid + VAR_OID_PREFETCH);
|
||||
ShmemVariableCache->oidCount = VAR_OID_PREFETCH;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* 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;
|
||||
lastSeenOid = (*oid_return) = ShmemVariableCache->nextOid;
|
||||
|
||||
next_prefetched_oid++;
|
||||
prefetched_oid_count--;
|
||||
(ShmemVariableCache->nextOid)++;
|
||||
(ShmemVariableCache->oidCount)--;
|
||||
|
||||
SpinRelease(OidGenLockId);
|
||||
}
|
||||
|
||||
void
|
||||
CheckMaxObjectId(Oid assigned_oid)
|
||||
{
|
||||
Oid temp_oid;
|
||||
|
||||
if (prefetched_oid_count == 0) /* make sure next/max is set, or
|
||||
* reload */
|
||||
GetNewObjectId(&temp_oid);
|
||||
|
||||
/* ----------------
|
||||
* If we are below prefetched limits, do nothing
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
if (assigned_oid < next_prefetched_oid)
|
||||
if (lastSeenOid != InvalidOid && assigned_oid < lastSeenOid)
|
||||
return;
|
||||
|
||||
/* ----------------
|
||||
* If we are here, we are coming from a 'copy from' with oid's
|
||||
*
|
||||
* If we are in the prefetched oid range, just bump it up
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
if (assigned_oid <= next_prefetched_oid + prefetched_oid_count - 1)
|
||||
SpinAcquire(OidGenLockId);
|
||||
if (assigned_oid < ShmemVariableCache->nextOid)
|
||||
{
|
||||
prefetched_oid_count -= assigned_oid - next_prefetched_oid + 1;
|
||||
next_prefetched_oid = assigned_oid + 1;
|
||||
lastSeenOid = ShmemVariableCache->nextOid - 1;
|
||||
SpinRelease(OidGenLockId);
|
||||
return;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* We have exceeded the prefetch oid range
|
||||
*
|
||||
* We should lock the database and kill all other backends
|
||||
* but we are loading oid's that we can not guarantee are unique
|
||||
* anyway, so we must rely on the user
|
||||
*
|
||||
* We now:
|
||||
* set the variable relation with the new max oid
|
||||
* force the backend to reload its oid cache
|
||||
*
|
||||
* By reloading the oid cache, we don't have to update the variable
|
||||
* relation every time when sequential OIDs are being loaded by COPY.
|
||||
* ----------------
|
||||
/* If we are in the logged oid range, just bump nextOid up */
|
||||
if (assigned_oid <= ShmemVariableCache->nextOid +
|
||||
ShmemVariableCache->oidCount - 1)
|
||||
{
|
||||
ShmemVariableCache->oidCount -=
|
||||
assigned_oid - ShmemVariableCache->nextOid + 1;
|
||||
ShmemVariableCache->nextOid = assigned_oid + 1;
|
||||
SpinRelease(OidGenLockId);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have exceeded the logged oid range.
|
||||
* We should lock the database and kill all other backends
|
||||
* but we are loading oid's that we can not guarantee are unique
|
||||
* anyway, so we must rely on the user.
|
||||
*/
|
||||
|
||||
SpinAcquire(OidGenLockId);
|
||||
VariableRelationPutNextOid(assigned_oid);
|
||||
XLogPutNextOid(assigned_oid + VAR_OID_PREFETCH);
|
||||
ShmemVariableCache->oidCount = VAR_OID_PREFETCH - 1;
|
||||
ShmemVariableCache->nextOid = assigned_oid + 1;
|
||||
|
||||
SpinRelease(OidGenLockId);
|
||||
|
||||
prefetched_oid_count = 0; /* force reload */
|
||||
GetNewObjectId(&temp_oid); /* cause target OID to be allocated */
|
||||
}
|
||||
|
||||
#endif /* !XLOG */
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.85 2000/11/30 01:47:31 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.86 2000/11/30 08:46:22 vadim Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Transaction aborts can now occur two ways:
|
||||
@@ -219,7 +219,6 @@ TransactionState CurrentTransactionState = &CurrentTransactionStateData;
|
||||
int DefaultXactIsoLevel = XACT_READ_COMMITTED;
|
||||
int XactIsoLevel;
|
||||
|
||||
#ifdef XLOG
|
||||
#include "access/xlogutils.h"
|
||||
|
||||
int CommitDelay = 5; /* 1/200000 sec */
|
||||
@@ -227,8 +226,6 @@ int CommitDelay = 5; /* 1/200000 sec */
|
||||
static void (*_RollbackFunc)(void*) = NULL;
|
||||
static void *_RollbackData = NULL;
|
||||
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* info returned when the system is disabled
|
||||
*
|
||||
@@ -662,19 +659,10 @@ RecordTransactionCommit()
|
||||
TransactionId xid;
|
||||
int leak;
|
||||
|
||||
/* ----------------
|
||||
* get the current transaction id
|
||||
* ----------------
|
||||
*/
|
||||
xid = GetCurrentTransactionId();
|
||||
|
||||
/*
|
||||
* flush the buffer manager pages. Note: if we have stable main
|
||||
* memory, dirty shared buffers are not flushed plai 8/7/90
|
||||
*/
|
||||
leak = BufferPoolCheckLeak();
|
||||
|
||||
#ifdef XLOG
|
||||
if (MyLastRecPtr.xrecoff != 0)
|
||||
{
|
||||
xl_xact_commit xlrec;
|
||||
@@ -685,7 +673,7 @@ RecordTransactionCommit()
|
||||
|
||||
xlrec.xtime = time(NULL);
|
||||
/*
|
||||
* MUST SAVE ARRAY OF RELFILENODE-s TO DROP
|
||||
* SHOULD SAVE ARRAY OF RELFILENODE-s TO DROP
|
||||
*/
|
||||
recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_COMMIT,
|
||||
(char*) &xlrec, SizeOfXactCommit, NULL, 0);
|
||||
@@ -704,30 +692,6 @@ RecordTransactionCommit()
|
||||
|
||||
MyProc->logRec.xrecoff = 0;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* If no one shared buffer was changed by this transaction then we
|
||||
* don't flush shared buffers and don't record commit status.
|
||||
*/
|
||||
if (SharedBufferChanged)
|
||||
{
|
||||
FlushBufferPool();
|
||||
if (leak)
|
||||
ResetBufferPool(true);
|
||||
|
||||
/*
|
||||
* have the transaction access methods record the status of this
|
||||
* transaction id in the pg_log relation.
|
||||
*/
|
||||
TransactionIdCommit(xid);
|
||||
|
||||
/*
|
||||
* Now write the log info to the disk too.
|
||||
*/
|
||||
leak = BufferPoolCheckLeak();
|
||||
FlushBufferPool();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (leak)
|
||||
ResetBufferPool(true);
|
||||
@@ -815,23 +779,8 @@ AtCommit_Memory(void)
|
||||
static void
|
||||
RecordTransactionAbort(void)
|
||||
{
|
||||
TransactionId xid;
|
||||
TransactionId xid = GetCurrentTransactionId();
|
||||
|
||||
/* ----------------
|
||||
* get the current transaction id
|
||||
* ----------------
|
||||
*/
|
||||
xid = GetCurrentTransactionId();
|
||||
|
||||
/*
|
||||
* Have the transaction access methods record the status of this
|
||||
* transaction id in the pg_log relation. We skip it if no one shared
|
||||
* buffer was changed by this transaction.
|
||||
*/
|
||||
if (SharedBufferChanged && !TransactionIdDidCommit(xid))
|
||||
TransactionIdAbort(xid);
|
||||
|
||||
#ifdef XLOG
|
||||
if (MyLastRecPtr.xrecoff != 0)
|
||||
{
|
||||
xl_xact_abort xlrec;
|
||||
@@ -841,9 +790,9 @@ RecordTransactionAbort(void)
|
||||
recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_ABORT,
|
||||
(char*) &xlrec, SizeOfXactAbort, NULL, 0);
|
||||
|
||||
TransactionIdAbort(xid);
|
||||
MyProc->logRec.xrecoff = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Tell bufmgr and smgr to release resources.
|
||||
@@ -1748,8 +1697,6 @@ IsTransactionBlock(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef XLOG
|
||||
|
||||
void
|
||||
xact_redo(XLogRecPtr lsn, XLogRecord *record)
|
||||
{
|
||||
@@ -1760,7 +1707,7 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record)
|
||||
xl_xact_commit *xlrec = (xl_xact_commit*) XLogRecGetData(record);
|
||||
|
||||
TransactionIdCommit(record->xl_xid);
|
||||
/* MUST REMOVE FILES OF ALL DROPPED RELATIONS */
|
||||
/* SHOULD REMOVE FILES OF ALL DROPPED RELATIONS */
|
||||
}
|
||||
else if (info == XLOG_XACT_ABORT)
|
||||
{
|
||||
@@ -1825,5 +1772,3 @@ XactPopRollback(void)
|
||||
{
|
||||
_RollbackFunc = NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.37 2000/11/30 01:47:31 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.38 2000/11/30 08:46:22 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1443,12 +1443,10 @@ void
|
||||
BootStrapXLOG()
|
||||
{
|
||||
CheckPoint checkPoint;
|
||||
#ifdef XLOG
|
||||
char buffer[BLCKSZ];
|
||||
bool usexistent = false;
|
||||
XLogPageHeader page = (XLogPageHeader) buffer;
|
||||
XLogRecord *record;
|
||||
#endif
|
||||
|
||||
checkPoint.redo.xlogid = 0;
|
||||
checkPoint.redo.xrecoff = SizeOfXLogPHD;
|
||||
@@ -1462,8 +1460,6 @@ BootStrapXLOG()
|
||||
ShmemVariableCache->nextOid = checkPoint.nextOid;
|
||||
ShmemVariableCache->oidCount = 0;
|
||||
|
||||
#ifdef XLOG
|
||||
|
||||
memset(buffer, 0, BLCKSZ);
|
||||
page->xlp_magic = XLOG_PAGE_MAGIC;
|
||||
page->xlp_info = 0;
|
||||
@@ -1488,8 +1484,6 @@ BootStrapXLOG()
|
||||
close(logFile);
|
||||
logFile = -1;
|
||||
|
||||
#endif
|
||||
|
||||
memset(ControlFile, 0, sizeof(ControlFileData));
|
||||
ControlFile->logId = 0;
|
||||
ControlFile->logSeg = 1;
|
||||
@@ -1513,14 +1507,12 @@ str_time(time_t tnow)
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This func must be called ONCE on system startup
|
||||
*/
|
||||
void
|
||||
StartupXLOG()
|
||||
{
|
||||
#ifdef XLOG
|
||||
XLogCtlInsert *Insert;
|
||||
CheckPoint checkPoint;
|
||||
XLogRecPtr RecPtr,
|
||||
@@ -1529,8 +1521,6 @@ StartupXLOG()
|
||||
char buffer[MAXLOGRECSZ + SizeOfXLogRecord];
|
||||
bool sie_saved = false;
|
||||
|
||||
#endif
|
||||
|
||||
elog(LOG, "starting up");
|
||||
|
||||
XLogCtl->xlblocks = (XLogRecPtr *) (((char *) XLogCtl) + sizeof(XLogCtlData));
|
||||
@@ -1580,8 +1570,6 @@ StartupXLOG()
|
||||
elog(LOG, "database system was interrupted at %s",
|
||||
str_time(ControlFile->time));
|
||||
|
||||
#ifdef XLOG
|
||||
|
||||
LastRec = RecPtr = ControlFile->checkPoint;
|
||||
if (!XRecOffIsValid(RecPtr.xrecoff))
|
||||
elog(STOP, "Invalid checkPoint in control file");
|
||||
@@ -1602,12 +1590,7 @@ StartupXLOG()
|
||||
checkPoint.nextXid, checkPoint.nextOid);
|
||||
if (checkPoint.nextXid < FirstTransactionId ||
|
||||
checkPoint.nextOid < BootstrapObjectIdData)
|
||||
|
||||
#ifdef XLOG_2
|
||||
elog(STOP, "Invalid NextTransactionId/NextOid");
|
||||
#else
|
||||
elog(LOG, "Invalid NextTransactionId/NextOid");
|
||||
#endif
|
||||
|
||||
ShmemVariableCache->nextXid = checkPoint.nextXid;
|
||||
ShmemVariableCache->nextOid = checkPoint.nextOid;
|
||||
@@ -1751,8 +1734,6 @@ StartupXLOG()
|
||||
}
|
||||
InRecovery = false;
|
||||
|
||||
#endif /* XLOG */
|
||||
|
||||
ControlFile->state = DB_IN_PRODUCTION;
|
||||
ControlFile->time = time(NULL);
|
||||
UpdateControlFile();
|
||||
@@ -1783,9 +1764,7 @@ ShutdownXLOG()
|
||||
{
|
||||
elog(LOG, "shutting down");
|
||||
|
||||
#ifdef XLOG
|
||||
CreateDummyCaches();
|
||||
#endif
|
||||
CreateCheckPoint(true);
|
||||
|
||||
elog(LOG, "database system is shut down");
|
||||
@@ -1796,7 +1775,6 @@ extern XLogRecPtr GetUndoRecPtr(void);
|
||||
void
|
||||
CreateCheckPoint(bool shutdown)
|
||||
{
|
||||
#ifdef XLOG
|
||||
CheckPoint checkPoint;
|
||||
XLogRecPtr recptr;
|
||||
XLogCtlInsert *Insert = &XLogCtl->Insert;
|
||||
@@ -1880,12 +1858,9 @@ CreateCheckPoint(bool shutdown)
|
||||
|
||||
XLogFlush(recptr);
|
||||
|
||||
#endif /* XLOG */
|
||||
|
||||
SpinAcquire(ControlFileLockId);
|
||||
if (shutdown)
|
||||
ControlFile->state = DB_SHUTDOWNED;
|
||||
#ifdef XLOG
|
||||
else /* create new log file */
|
||||
{
|
||||
if (recptr.xrecoff % XLogSegSize >=
|
||||
@@ -1914,16 +1889,10 @@ CreateCheckPoint(bool shutdown)
|
||||
_logSeg = ControlFile->logSeg - 1;
|
||||
strcpy(archdir, ControlFile->archdir);
|
||||
|
||||
#else
|
||||
ControlFile->checkPoint.xlogid = 0;
|
||||
ControlFile->checkPoint.xrecoff = SizeOfXLogPHD;
|
||||
#endif
|
||||
|
||||
ControlFile->time = time(NULL);
|
||||
UpdateControlFile();
|
||||
SpinRelease(ControlFileLockId);
|
||||
|
||||
#ifdef XLOG
|
||||
/*
|
||||
* Delete offline log files. Get oldest online
|
||||
* log file from undo rec if it's valid.
|
||||
@@ -1948,7 +1917,6 @@ CreateCheckPoint(bool shutdown)
|
||||
S_UNLOCK(&(XLogCtl->chkp_lck));
|
||||
|
||||
MyLastRecPtr.xrecoff = 0; /* to avoid commit record */
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* varsup.c
|
||||
* postgres OID & XID variables support routines
|
||||
*
|
||||
* Copyright (c) 2000, PostgreSQL, Inc
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/xlog_varsup.c,v 1.1 2000/11/03 11:39:35 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/transam.h"
|
||||
#include "storage/proc.h"
|
||||
|
||||
SPINLOCK OidGenLockId;
|
||||
|
||||
extern SPINLOCK XidGenLockId;
|
||||
extern void XLogPutNextOid(Oid nextOid);
|
||||
|
||||
/* pointer to "variable cache" in shared memory (set up by shmem.c) */
|
||||
VariableCache ShmemVariableCache = NULL;
|
||||
|
||||
void
|
||||
GetNewTransactionId(TransactionId *xid)
|
||||
{
|
||||
/*
|
||||
* During bootstrap initialization, we return the special
|
||||
* bootstrap transaction id.
|
||||
*/
|
||||
if (AMI_OVERRIDE)
|
||||
{
|
||||
*xid = AmiTransactionId;
|
||||
return;
|
||||
}
|
||||
|
||||
SpinAcquire(XidGenLockId);
|
||||
*xid = ShmemVariableCache->nextXid;
|
||||
(ShmemVariableCache->nextXid)++;
|
||||
|
||||
if (MyProc != (PROC *) NULL)
|
||||
MyProc->xid = *xid;
|
||||
|
||||
SpinRelease(XidGenLockId);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Like GetNewTransactionId reads nextXid but don't fetch it.
|
||||
*/
|
||||
void
|
||||
ReadNewTransactionId(TransactionId *xid)
|
||||
{
|
||||
|
||||
/*
|
||||
* During bootstrap initialization, we return the special
|
||||
* bootstrap transaction id.
|
||||
*/
|
||||
if (AMI_OVERRIDE)
|
||||
{
|
||||
*xid = AmiTransactionId;
|
||||
return;
|
||||
}
|
||||
|
||||
SpinAcquire(XidGenLockId);
|
||||
*xid = ShmemVariableCache->nextXid;
|
||||
SpinRelease(XidGenLockId);
|
||||
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* object id generation support
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define VAR_OID_PREFETCH 8192
|
||||
static Oid lastSeenOid = InvalidOid;
|
||||
|
||||
void
|
||||
GetNewObjectId(Oid *oid_return)
|
||||
{
|
||||
SpinAcquire(OidGenLockId);
|
||||
|
||||
/* If we run out of logged for use oids then we log more */
|
||||
if (ShmemVariableCache->oidCount == 0)
|
||||
{
|
||||
XLogPutNextOid(ShmemVariableCache->nextOid + VAR_OID_PREFETCH);
|
||||
ShmemVariableCache->oidCount = VAR_OID_PREFETCH;
|
||||
}
|
||||
|
||||
if (PointerIsValid(oid_return))
|
||||
lastSeenOid = (*oid_return) = ShmemVariableCache->nextOid;
|
||||
|
||||
(ShmemVariableCache->nextOid)++;
|
||||
(ShmemVariableCache->oidCount)--;
|
||||
|
||||
SpinRelease(OidGenLockId);
|
||||
}
|
||||
|
||||
void
|
||||
CheckMaxObjectId(Oid assigned_oid)
|
||||
{
|
||||
|
||||
if (lastSeenOid != InvalidOid && assigned_oid < lastSeenOid)
|
||||
return;
|
||||
|
||||
SpinAcquire(OidGenLockId);
|
||||
if (assigned_oid < ShmemVariableCache->nextOid)
|
||||
{
|
||||
lastSeenOid = ShmemVariableCache->nextOid - 1;
|
||||
SpinRelease(OidGenLockId);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If we are in the logged oid range, just bump nextOid up */
|
||||
if (assigned_oid <= ShmemVariableCache->nextOid +
|
||||
ShmemVariableCache->oidCount - 1)
|
||||
{
|
||||
ShmemVariableCache->oidCount -=
|
||||
assigned_oid - ShmemVariableCache->nextOid + 1;
|
||||
ShmemVariableCache->nextOid = assigned_oid + 1;
|
||||
SpinRelease(OidGenLockId);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have exceeded the logged oid range.
|
||||
* We should lock the database and kill all other backends
|
||||
* but we are loading oid's that we can not guarantee are unique
|
||||
* anyway, so we must rely on the user.
|
||||
*/
|
||||
|
||||
XLogPutNextOid(assigned_oid + VAR_OID_PREFETCH);
|
||||
ShmemVariableCache->oidCount = VAR_OID_PREFETCH - 1;
|
||||
ShmemVariableCache->nextOid = assigned_oid + 1;
|
||||
|
||||
SpinRelease(OidGenLockId);
|
||||
|
||||
}
|
||||
@@ -10,9 +10,6 @@
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#ifdef XLOG
|
||||
|
||||
#include "access/xlog.h"
|
||||
#include "access/transam.h"
|
||||
#include "access/xact.h"
|
||||
@@ -397,5 +394,3 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
|
||||
|
||||
return(&(res->reldata));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user