transam.h 5.8 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * transam.h
4
 *	  postgres transaction access method support code header
5 6
 *
 *
7
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
B
Bruce Momjian 已提交
10
 * $Id: transam.h,v 1.32 2001/03/22 04:00:31 momjian Exp $
11
 *
12 13 14
 *	 NOTES
 *		Transaction System Version 101 now support proper oid
 *		generation and recording in the variable relation.
15 16 17 18 19 20
 *
 *-------------------------------------------------------------------------
 */
#ifndef TRANSAM_H
#define TRANSAM_H

21
#include "storage/bufmgr.h"
22

23
/* ----------------
24
 *		transaction system version id
25
 *
26 27 28 29
 *		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.
30
 *
31 32 33
 *		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.
34 35
 * ----------------
 */
V
Vadim B. Mikheev 已提交
36
#define TRANS_SYSTEM_VERSION	200
37 38

/* ----------------
39
 *		transaction id status values
40
 *
V
Vadim B. Mikheev 已提交
41 42
 *		someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
 *		commiting of child xactions.
43 44
 * ----------------
 */
45 46 47 48
#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 */
49

50
typedef unsigned char XidStatus;/* (2 bits) */
51 52

/* ----------
53 54 55
 *		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.
56 57 58 59 60
 * ----------
 */
#define BootstrapObjectIdData 16384

/* ----------------
61
 *		BitIndexOf computes the index of the Nth xid on a given block
62 63
 * ----------------
 */
64
#define BitIndexOf(N)	((N) * 2)
65 66

/* ----------------
67
 *		transaction page definitions
68 69
 * ----------------
 */
V
WAL  
Vadim B. Mikheev 已提交
70
#define TP_DataSize				(BLCKSZ - sizeof(XLogRecPtr))
71
#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
72 73

/* ----------------
74
 *		LogRelationContents structure
75
 *
76 77 78 79
 *		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.
80
 *
81
 *		The first 4 bytes of this relation store the version
T
Tom Lane 已提交
82
 *		number of the transaction system.
83 84
 * ----------------
 */
85 86
typedef struct LogRelationContentsData
{
B
Bruce Momjian 已提交
87 88
	XLogRecPtr	LSN;			/* temp hack: LSN is member of any block */
	/* so should be described in bufmgr */
89
	int			TransSystemVersion;
90
} LogRelationContentsData;
91 92 93 94

typedef LogRelationContentsData *LogRelationContents;

/* ----------------
95
 *		VariableRelationContents structure
96
 *
97 98 99 100
 *		The variable relation is a special "relation" which
 *		is used to store various system "variables" persistantly.
 *		Unlike other relations in the system, this relation
 *		is updated in place whenever the variables change.
101
 *
102
 *		The first 4 bytes of this relation store the version
T
Tom Lane 已提交
103
 *		number of the transaction system.
104
 *
105 106 107
 *		Currently, the relation has only one page and the next
 *		available xid, the last committed xid and the next
 *		available oid are stored there.
T
Tom Lane 已提交
108 109
 *
 *		XXX As of 7.1, pg_variable isn't used anymore; this is dead code.
110 111
 * ----------------
 */
T
Tom Lane 已提交
112
#ifdef NOT_USED
113 114
typedef struct VariableRelationContentsData
{
V
WAL  
Vadim B. Mikheev 已提交
115
	XLogRecPtr	LSN;
116 117 118 119
	int			TransSystemVersion;
	TransactionId nextXidData;
	TransactionId lastXidData;	/* unused */
	Oid			nextOid;
120
} VariableRelationContentsData;
121 122

typedef VariableRelationContentsData *VariableRelationContents;
B
Bruce Momjian 已提交
123 124

#endif	 /* NOT_USED */
125

126
/*
V
Vadim B. Mikheev 已提交
127 128
 * VariableCache is placed in shmem and used by
 * backends to get next available XID & OID.
129 130 131
 */
typedef struct VariableCacheData
{
B
Bruce Momjian 已提交
132 133 134
	TransactionId nextXid;		/* next XID to assign */
	Oid			nextOid;		/* next OID to assign */
	uint32		oidCount;		/* OIDs available before must do XLOG work */
135
} VariableCacheData;
136

137
typedef VariableCacheData *VariableCache;
138

139
/* ----------------
140
 *		extern declarations
141 142 143 144 145 146
 * ----------------
 */

/*
 * prototypes for functions in transam/transam.c
 */
147 148 149 150 151
extern void InitializeTransactionLog(void);
extern bool TransactionIdDidCommit(TransactionId transactionId);
extern bool TransactionIdDidAbort(TransactionId transactionId);
extern void TransactionIdCommit(TransactionId transactionId);
extern void TransactionIdAbort(TransactionId transactionId);
152 153

/* in transam/transsup.c */
154
extern void AmiTransactionOverride(bool flag);
155
extern void TransComputeBlockNumber(Relation relation,
B
Bruce Momjian 已提交
156
			  TransactionId transactionId, BlockNumber *blockNumberOutP);
157
extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
158
				BlockNumber blockNumber, TransactionId xid, bool *failP);
159
extern void TransBlockNumberSetXidStatus(Relation relation,
160
		   BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
161
							 bool *failP);
162 163

/* in transam/varsup.c */
164
extern void VariableRelationPutNextXid(TransactionId xid);
165
extern void GetNewTransactionId(TransactionId *xid);
166
extern void ReadNewTransactionId(TransactionId *xid);
167
extern void GetNewObjectId(Oid *oid_return);
168
extern void CheckMaxObjectId(Oid assigned_oid);
169 170

/* ----------------
171
 *		global variable extern declarations
172 173 174 175
 * ----------------
 */

/* in transam.c */
176 177
extern Relation LogRelation;
extern Relation VariableRelation;
178

179 180
extern TransactionId cachedTestXid;
extern XidStatus cachedTestXidStatus;
181 182 183 184 185

extern TransactionId NullTransactionId;
extern TransactionId AmiTransactionId;
extern TransactionId FirstTransactionId;

186
extern int	RecoveryCheckingEnableState;
187 188

/* in transsup.c */
189
extern bool AMI_OVERRIDE;
190 191

/* in varsup.c */
T
Tom Lane 已提交
192 193
extern SPINLOCK OidGenLockId;
extern SPINLOCK XidGenLockId;
194
extern VariableCache ShmemVariableCache;
195

196
#endif	 /* TRAMSAM_H */