postgresql/src/include/access/transam.h

163 lines
4.8 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* transam.h
* postgres transaction access method support code header
*
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: transam.h,v 1.35 2001/05/25 15:45:33 momjian Exp $
*
* NOTES
* Transaction System Version 101 now support proper oid
* generation and recording in the variable relation.
*
*-------------------------------------------------------------------------
*/
#ifndef TRANSAM_H
#define TRANSAM_H
#include "storage/bufmgr.h"
/* ----------------
* transaction system version id
*
* this is stored on the first page of the log, time and variable
* relations on the first 4 bytes. This is so that if we improve
* the format of the transaction log after postgres version 2, then
* people won't have to rebuild their databases.
*
* TRANS_SYSTEM_VERSION 100 means major version 1 minor version 0.
* Two databases with the same major version should be compatible,
* even if their minor versions differ.
* ----------------
*/
1997-11-02 16:27:14 +01:00
#define TRANS_SYSTEM_VERSION 200
/* ----------------
* transaction id status values
*
1997-11-02 16:27:14 +01:00
* someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
* commiting of child xactions.
* ----------------
*/
#define XID_COMMIT 2 /* transaction commited */
#define XID_ABORT 1 /* transaction aborted */
#define XID_INPROGRESS 0 /* transaction in progress */
#define XID_COMMIT_CHILD 3 /* child xact commited */
typedef unsigned char XidStatus;/* (2 bits) */
/* ----------
* 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
/* ----------------
* BitIndexOf computes the index of the Nth xid on a given block
* ----------------
*/
#define BitIndexOf(N) ((N) * 2)
/* ----------------
* transaction page definitions
* ----------------
*/
2000-10-28 18:21:00 +02:00
#define TP_DataSize (BLCKSZ - sizeof(XLogRecPtr))
#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
/* ----------------
* LogRelationContents structure
*
* This structure describes the storage of the data in the
* first 128 bytes of the log relation. This storage is never
* used for transaction status because transaction id's begin
* their numbering at 512.
*
* The first 4 bytes of this relation store the version
XLOG (and related) changes: * Store two past checkpoint locations, not just one, in pg_control. On startup, we fall back to the older checkpoint if the newer one is unreadable. Also, a physical copy of the newest checkpoint record is kept in pg_control for possible use in disaster recovery (ie, complete loss of pg_xlog). Also add a version number for pg_control itself. Remove archdir from pg_control; it ought to be a GUC parameter, not a special case (not that it's implemented yet anyway). * Suppress successive checkpoint records when nothing has been entered in the WAL log since the last one. This is not so much to avoid I/O as to make it actually useful to keep track of the last two checkpoints. If the things are right next to each other then there's not a lot of redundancy gained... * Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs on alternate bytes. Polynomial borrowed from ECMA DLT1 standard. * Fix XLOG record length handling so that it will work at BLCKSZ = 32k. * Change XID allocation to work more like OID allocation. (This is of dubious necessity, but I think it's a good idea anyway.) * Fix a number of minor bugs, such as off-by-one logic for XLOG file wraparound at the 4 gig mark. * Add documentation and clean up some coding infelicities; move file format declarations out to include files where planned contrib utilities can get at them. * Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also possible to force a checkpoint by sending SIGUSR1 to the postmaster (undocumented feature...) * Defend against kill -9 postmaster by storing shmem block's key and ID in postmaster.pid lockfile, and checking at startup to ensure that no processes are still connected to old shmem block (if it still exists). * Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency stop, for symmetry with postmaster and xlog utilities. Clean up signal handling in bootstrap.c so that xlog utilities launched by postmaster will react to signals better. * Standalone bootstrap now grabs lockfile in target directory, as added insurance against running it in parallel with live postmaster.
2001-03-13 02:17:06 +01:00
* number of the transaction system.
* ----------------
*/
typedef struct LogRelationContentsData
{
2001-03-22 05:01:46 +01:00
XLogRecPtr LSN; /* temp hack: LSN is member of any block */
/* so should be described in bufmgr */
int TransSystemVersion;
} LogRelationContentsData;
typedef LogRelationContentsData *LogRelationContents;
/*
2000-11-30 09:46:26 +01:00
* VariableCache is placed in shmem and used by
* backends to get next available XID & OID.
*/
typedef struct VariableCacheData
{
2001-03-22 05:01:46 +01:00
TransactionId nextXid; /* next XID to assign */
Oid nextOid; /* next OID to assign */
uint32 oidCount; /* OIDs available before must do XLOG work */
1999-05-26 00:43:53 +02:00
} VariableCacheData;
typedef VariableCacheData *VariableCache;
/* ----------------
* extern declarations
* ----------------
*/
/*
* prototypes for functions in transam/transam.c
*/
extern void InitializeTransactionLog(void);
extern bool TransactionIdDidCommit(TransactionId transactionId);
extern bool TransactionIdDidAbort(TransactionId transactionId);
extern void TransactionIdCommit(TransactionId transactionId);
extern void TransactionIdAbort(TransactionId transactionId);
/* in transam/transsup.c */
extern void AmiTransactionOverride(bool flag);
extern void TransComputeBlockNumber(Relation relation,
1997-09-08 22:59:27 +02:00
TransactionId transactionId, BlockNumber *blockNumberOutP);
extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
BlockNumber blockNumber, TransactionId xid, bool *failP);
extern void TransBlockNumberSetXidStatus(Relation relation,
BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
bool *failP);
/* in transam/varsup.c */
extern void GetNewTransactionId(TransactionId *xid);
extern void ReadNewTransactionId(TransactionId *xid);
extern void GetNewObjectId(Oid *oid_return);
extern void CheckMaxObjectId(Oid assigned_oid);
/* ----------------
* global variable extern declarations
* ----------------
*/
/* in transam.c */
extern Relation LogRelation;
extern TransactionId cachedTestXid;
extern XidStatus cachedTestXidStatus;
extern TransactionId NullTransactionId;
extern TransactionId AmiTransactionId;
extern TransactionId FirstTransactionId;
extern int RecoveryCheckingEnableState;
/* in transsup.c */
extern bool AMI_OVERRIDE;
/* in varsup.c */
XLOG (and related) changes: * Store two past checkpoint locations, not just one, in pg_control. On startup, we fall back to the older checkpoint if the newer one is unreadable. Also, a physical copy of the newest checkpoint record is kept in pg_control for possible use in disaster recovery (ie, complete loss of pg_xlog). Also add a version number for pg_control itself. Remove archdir from pg_control; it ought to be a GUC parameter, not a special case (not that it's implemented yet anyway). * Suppress successive checkpoint records when nothing has been entered in the WAL log since the last one. This is not so much to avoid I/O as to make it actually useful to keep track of the last two checkpoints. If the things are right next to each other then there's not a lot of redundancy gained... * Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs on alternate bytes. Polynomial borrowed from ECMA DLT1 standard. * Fix XLOG record length handling so that it will work at BLCKSZ = 32k. * Change XID allocation to work more like OID allocation. (This is of dubious necessity, but I think it's a good idea anyway.) * Fix a number of minor bugs, such as off-by-one logic for XLOG file wraparound at the 4 gig mark. * Add documentation and clean up some coding infelicities; move file format declarations out to include files where planned contrib utilities can get at them. * Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also possible to force a checkpoint by sending SIGUSR1 to the postmaster (undocumented feature...) * Defend against kill -9 postmaster by storing shmem block's key and ID in postmaster.pid lockfile, and checking at startup to ensure that no processes are still connected to old shmem block (if it still exists). * Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency stop, for symmetry with postmaster and xlog utilities. Clean up signal handling in bootstrap.c so that xlog utilities launched by postmaster will react to signals better. * Standalone bootstrap now grabs lockfile in target directory, as added insurance against running it in parallel with live postmaster.
2001-03-13 02:17:06 +01:00
extern SPINLOCK OidGenLockId;
extern SPINLOCK XidGenLockId;
extern VariableCache ShmemVariableCache;
#endif /* TRAMSAM_H */