transam.h 5.5 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
 *
9
 * $Id: transam.h,v 1.15 1998/07/21 06:17:39 vadim 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 127 128 129 130 131 132 133 134
/*
 * 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
{
	uint32			xid_count;
	TransactionId	nextXid;
	uint32			oid_count;		/* not implemented, yet */
	Oid				nextOid;
} VariableCacheData;

typedef VariableCacheData	   *VariableCache;

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);
148 149

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

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

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

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

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

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

184
extern int	RecoveryCheckingEnableState;
185 186

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

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

192
#endif							/* TRAMSAM_H */