transam.h 5.6 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * transam.h
4
 *	  postgres transaction access method support code header
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
B
Bruce Momjian 已提交
9
 * $Id: transam.h,v 1.20 1999/05/25 16:13:35 momjian Exp $
10
 *
11 12 13
 *	 NOTES
 *		Transaction System Version 101 now support proper oid
 *		generation and recording in the variable relation.
14 15 16 17 18 19
 *
 *-------------------------------------------------------------------------
 */
#ifndef TRANSAM_H
#define TRANSAM_H

M
Marc G. Fournier 已提交
20
#include <storage/bufmgr.h>
21

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

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

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

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

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

/* ----------------
66
 *		transaction page definitions
67 68
 * ----------------
 */
69 70
#define TP_DataSize				BLCKSZ
#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
71 72

/* ----------------
73
 *		LogRelationContents structure
74
 *
75 76 77 78
 *		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.
79
 *
80 81
 *		The first 4 bytes of this relation store the version
 *		number of the transction system.
82 83
 * ----------------
 */
84 85
typedef struct LogRelationContentsData
{
86
	int			TransSystemVersion;
87
} LogRelationContentsData;
88 89 90 91

typedef LogRelationContentsData *LogRelationContents;

/* ----------------
92
 *		VariableRelationContents structure
93
 *
94 95 96 97
 *		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.
98
 *
99 100
 *		The first 4 bytes of this relation store the version
 *		number of the transction system.
101
 *
102 103 104
 *		Currently, the relation has only one page and the next
 *		available xid, the last committed xid and the next
 *		available oid are stored there.
105 106
 * ----------------
 */
107 108
typedef struct VariableRelationContentsData
{
109 110 111 112
	int			TransSystemVersion;
	TransactionId nextXidData;
	TransactionId lastXidData;	/* unused */
	Oid			nextOid;
113
} VariableRelationContentsData;
114 115 116

typedef VariableRelationContentsData *VariableRelationContents;

117 118 119 120 121 122 123 124 125 126
/*
 * VariableCache is placed in shmem and used by backends to
 * get next available XID & OID without access to
 * variable relation. Actually, I would like to have two
 * different on-disk storages for next XID and OID...
 * But hoping that someday we will use per database OID
 * generator I leaved this as is.	- vadim 07/21/98
 */
typedef struct VariableCacheData
{
127 128 129 130 131
	uint32		xid_count;
	TransactionId nextXid;
	uint32		oid_count;		/* not implemented, yet */
	Oid			nextOid;
}			VariableCacheData;
132

133
typedef VariableCacheData *VariableCache;
134

135
/* ----------------
136
 *		extern declarations
137 138 139 140 141 142
 * ----------------
 */

/*
 * prototypes for functions in transam/transam.c
 */
143 144 145 146 147
extern void InitializeTransactionLog(void);
extern bool TransactionIdDidCommit(TransactionId transactionId);
extern bool TransactionIdDidAbort(TransactionId transactionId);
extern void TransactionIdCommit(TransactionId transactionId);
extern void TransactionIdAbort(TransactionId transactionId);
B
Bruce Momjian 已提交
148
extern void TransactionIdFlushCache(void);
149 150

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

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

/* ----------------
168
 *		global variable extern declarations
169 170 171 172
 * ----------------
 */

/* in transam.c */
173 174
extern Relation LogRelation;
extern Relation VariableRelation;
175

176 177
extern TransactionId cachedTestXid;
extern XidStatus cachedTestXidStatus;
178 179 180 181 182

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

183
extern int	RecoveryCheckingEnableState;
184 185

/* in transsup.c */
186
extern bool AMI_OVERRIDE;
187 188

/* in varsup.c */
189
extern int	OidGenLockId;
190

191
#endif	 /* TRAMSAM_H */