transam.h 6.1 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.10 1997/09/08 20:58:12 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 21
#include <storage/bufmgr.h>
#include <utils/nabstime.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 36 37 38
 * ----------------
 */
#define TRANS_SYSTEM_VERSION	101

/* ----------------
39
 *		transaction id status values
40
 *
41 42
 *		someday we will use "11" = 3 = XID_INVALID to mean the
 *		starting of run-length encoded log data.
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_INVALID		3		/* other */
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
 * ----------------
 */
70 71 72
#define TP_DataSize				BLCKSZ
#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
#define TP_NumTimePerBlock		(TP_DataSize / 4)
73 74

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

typedef LogRelationContentsData *LogRelationContents;

/* ----------------
94
 *		TimeRelationContents structure
95
 *
96 97 98 99
 *		This structure describes the storage of the data in the
 *		first 2048 bytes of the time relation.	This storage is never
 *		used for transaction commit times because transaction id's begin
 *		their numbering at 512.
100
 *
101 102
 *		The first 4 bytes of this relation store the version
 *		number of the transction system.
103 104
 * ----------------
 */
105 106
typedef struct TimeRelationContentsData
{
107 108
	int			TransSystemVersion;
}			TimeRelationContentsData;
109 110 111 112

typedef TimeRelationContentsData *TimeRelationContents;

/* ----------------
113
 *		VariableRelationContents structure
114
 *
115 116 117 118
 *		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.
119
 *
120 121
 *		The first 4 bytes of this relation store the version
 *		number of the transction system.
122
 *
123 124 125
 *		Currently, the relation has only one page and the next
 *		available xid, the last committed xid and the next
 *		available oid are stored there.
126 127
 * ----------------
 */
128 129
typedef struct VariableRelationContentsData
{
130 131 132 133 134
	int			TransSystemVersion;
	TransactionId nextXidData;
	TransactionId lastXidData;
	Oid			nextOid;
}			VariableRelationContentsData;
135 136 137 138

typedef VariableRelationContentsData *VariableRelationContents;

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

/*
 * prototypes for functions in transam/transam.c
 */
extern AbsoluteTime TransactionIdGetCommitTime(TransactionId transactionId);
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 156
extern void
TransComputeBlockNumber(Relation relation,
B
Bruce Momjian 已提交
157
			  TransactionId transactionId, BlockNumber *blockNumberOutP);
158
extern		XidStatus
159 160 161 162 163 164
TransBlockNumberGetXidStatus(Relation relation,
			   BlockNumber blockNumber, TransactionId xid, bool * failP);
extern void
TransBlockNumberSetXidStatus(Relation relation,
		   BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
							 bool * failP);
B
Bruce Momjian 已提交
165
extern AbsoluteTime
166 167 168 169 170 171
TransBlockNumberGetCommitTime(Relation relation,
			   BlockNumber blockNumber, TransactionId xid, bool * failP);
extern void
TransBlockNumberSetCommitTime(Relation relation,
		  BlockNumber blockNumber, TransactionId xid, AbsoluteTime xtime,
							  bool * failP);
172 173

/* in transam/varsup.c */
174 175 176 177 178
extern void VariableRelationPutNextXid(TransactionId xid);
extern void GetNewTransactionId(TransactionId * xid);
extern void UpdateLastCommittedXid(TransactionId xid);
extern void GetNewObjectId(Oid * oid_return);
extern void CheckMaxObjectId(Oid assigned_oid);
179 180

/* ----------------
181
 *		global variable extern declarations
182 183 184 185
 * ----------------
 */

/* in transam.c */
186 187 188
extern Relation LogRelation;
extern Relation TimeRelation;
extern Relation VariableRelation;
189

190 191 192 193
extern TransactionId cachedGetCommitTimeXid;
extern AbsoluteTime cachedGetCommitTime;
extern TransactionId cachedTestXid;
extern XidStatus cachedTestXidStatus;
194 195 196 197 198

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

199
extern int	RecoveryCheckingEnableState;
200 201

/* in transsup.c */
202
extern bool AMI_OVERRIDE;
203 204

/* in varsup.c */
205
extern int	OidGenLockId;
206

207
#endif							/* TRAMSAM_H */