OSDN Git Service

Remove the mostly-stubbed-out-anyway support routines for WAL UNDO.
[pg-rex/syncrep.git] / src / include / access / xlog.h
1 /*
2  * xlog.h
3  *
4  * PostgreSQL transaction log manager
5  *
6  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.63 2005/06/06 17:01:24 tgl Exp $
10  */
11 #ifndef XLOG_H
12 #define XLOG_H
13
14 #include "access/rmgr.h"
15 #include "access/transam.h"
16 #include "access/xlogdefs.h"
17 #include "storage/buf.h"
18 #include "utils/pg_crc.h"
19
20
21 /*
22  * The overall layout of an XLOG record is:
23  *              Fixed-size header (XLogRecord struct)
24  *              rmgr-specific data
25  *              BkpBlock
26  *              backup block data
27  *              BkpBlock
28  *              backup block data
29  *              ...
30  *
31  * where there can be zero to three backup blocks (as signaled by xl_info flag
32  * bits).  XLogRecord structs always start on MAXALIGN boundaries in the WAL
33  * files, and we round up SizeOfXLogRecord so that the rmgr data is also
34  * guaranteed to begin on a MAXALIGN boundary.  However, no padding is added
35  * to align BkpBlock structs or backup block data.
36  *
37  * NOTE: xl_len counts only the rmgr data, not the XLogRecord header,
38  * and also not any backup blocks.  xl_tot_len counts everything.  Neither
39  * length field is rounded up to an alignment boundary.
40  */
41 typedef struct XLogRecord
42 {
43         pg_crc32        xl_crc;                 /* CRC for this record */
44         XLogRecPtr      xl_prev;                /* ptr to previous record in log */
45         TransactionId xl_xid;           /* xact id */
46         uint32          xl_tot_len;             /* total len of entire record */
47         uint32          xl_len;                 /* total len of rmgr data */
48         uint8           xl_info;                /* flag bits, see below */
49         RmgrId          xl_rmid;                /* resource manager for this record */
50
51         /* Depending on MAXALIGN, there are either 2 or 6 wasted bytes here */
52
53         /* ACTUAL LOG DATA FOLLOWS AT END OF STRUCT */
54
55 } XLogRecord;
56
57 #define SizeOfXLogRecord        MAXALIGN(sizeof(XLogRecord))
58
59 #define XLogRecGetData(record)  ((char*) (record) + SizeOfXLogRecord)
60
61 /*
62  * XLOG uses only low 4 bits of xl_info.  High 4 bits may be used by rmgr.
63  */
64 #define XLR_INFO_MASK                   0x0F
65
66 /*
67  * If we backed up any disk blocks with the XLOG record, we use flag bits in
68  * xl_info to signal it.  We support backup of up to 3 disk blocks per XLOG
69  * record.      (Could support 4 if we cared to dedicate all the xl_info bits for
70  * this purpose; currently bit 0 of xl_info is unused and available.)
71  */
72 #define XLR_BKP_BLOCK_MASK              0x0E    /* all info bits used for bkp
73                                                                                  * blocks */
74 #define XLR_MAX_BKP_BLOCKS              3
75 #define XLR_SET_BKP_BLOCK(iblk) (0x08 >> (iblk))
76 #define XLR_BKP_BLOCK_1                 XLR_SET_BKP_BLOCK(0)    /* 0x08 */
77 #define XLR_BKP_BLOCK_2                 XLR_SET_BKP_BLOCK(1)    /* 0x04 */
78 #define XLR_BKP_BLOCK_3                 XLR_SET_BKP_BLOCK(2)    /* 0x02 */
79
80 /*
81  * Sometimes we log records which are out of transaction control.
82  * Rmgr may "or" XLOG_NO_TRAN into info passed to XLogInsert to indicate this.
83  */
84 #define XLOG_NO_TRAN                    XLR_INFO_MASK
85
86 /* Sync methods */
87 #define SYNC_METHOD_FSYNC               0
88 #define SYNC_METHOD_FDATASYNC   1
89 #define SYNC_METHOD_OPEN                2                       /* for O_SYNC and O_DSYNC */
90 #define SYNC_METHOD_FSYNC_WRITETHROUGH  3
91 extern int      sync_method;
92
93 /*
94  * List of these structs is used to pass data to XLogInsert().
95  *
96  * If buffer is valid then XLOG will check if buffer must be backed up
97  * (ie, whether this is first change of that page since last checkpoint).
98  * If so, the whole page contents are attached to the XLOG record, and XLOG
99  * sets XLR_BKP_BLOCK_X bit in xl_info.  Note that the buffer must be pinned
100  * and locked while this is going on, so that it won't change under us.
101  * NB: when this happens, we do not bother to insert the associated data into
102  * the XLOG record, since we assume it's present in the buffer.  Therefore,
103  * rmgr redo routines MUST pay attention to XLR_BKP_BLOCK_X to know what
104  * is actually stored in the XLOG record.
105  */
106 typedef struct XLogRecData
107 {
108         Buffer          buffer;                 /* buffer associated with this data */
109         char       *data;
110         uint32          len;
111         struct XLogRecData *next;
112 } XLogRecData;
113
114 extern TimeLineID ThisTimeLineID;               /* current TLI */
115 extern bool InRecovery;
116 extern XLogRecPtr MyLastRecPtr;
117 extern bool MyXactMadeXLogEntry;
118 extern bool MyXactMadeTempRelUpdate;
119 extern XLogRecPtr ProcLastRecEnd;
120
121 /* these variables are GUC parameters related to XLOG */
122 extern int      CheckPointSegments;
123 extern int      XLOGbuffers;
124 extern char *XLogArchiveCommand;
125 extern char *XLOG_sync_method;
126 extern const char XLOG_sync_method_default[];
127
128 #define XLogArchivingActive()   (XLogArchiveCommand[0] != '\0')
129
130 #ifdef WAL_DEBUG
131 extern bool XLOG_DEBUG;
132 #endif
133
134 extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata);
135 extern void XLogFlush(XLogRecPtr RecPtr);
136
137 extern void xlog_redo(XLogRecPtr lsn, XLogRecord *record);
138 extern void xlog_desc(char *buf, uint8 xl_info, char *rec);
139
140 extern void UpdateControlFile(void);
141 extern int      XLOGShmemSize(void);
142 extern void XLOGShmemInit(void);
143 extern void XLOGPathInit(void);
144 extern void BootStrapXLOG(void);
145 extern void StartupXLOG(void);
146 extern void ShutdownXLOG(int code, Datum arg);
147 extern void InitXLOGAccess(void);
148 extern void CreateCheckPoint(bool shutdown, bool force);
149 extern void XLogPutNextOid(Oid nextOid);
150 extern void XLogPutNextMultiXactId(MultiXactId multi);
151 extern XLogRecPtr GetRedoRecPtr(void);
152
153 #endif   /* XLOG_H */