]> granicus.if.org Git - postgresql/blob - src/include/access/xlogrecord.h
Move the backup-block logic from XLogInsert to a new file, xloginsert.c.
[postgresql] / src / include / access / xlogrecord.h
1 /*
2  * xlogrecord.h
3  *
4  * Definitions for the WAL record format.
5  *
6  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/access/xlogrecord.h
10  */
11 #ifndef XLOGRECORD_H
12 #define XLOGRECORD_H
13
14 #include "access/rmgr.h"
15 #include "access/xlogdefs.h"
16 #include "storage/block.h"
17 #include "storage/relfilenode.h"
18 #include "utils/pg_crc.h"
19
20 /*
21  * The overall layout of an XLOG record is:
22  *              Fixed-size header (XLogRecord struct)
23  *              rmgr-specific data
24  *              BkpBlock
25  *              backup block data
26  *              BkpBlock
27  *              backup block data
28  *              ...
29  *
30  * where there can be zero to four backup blocks (as signaled by xl_info flag
31  * bits).  XLogRecord structs always start on MAXALIGN boundaries in the WAL
32  * files, and we round up SizeOfXLogRecord so that the rmgr data is also
33  * guaranteed to begin on a MAXALIGN boundary.  However, no padding is added
34  * to align BkpBlock structs or backup block data.
35  *
36  * NOTE: xl_len counts only the rmgr data, not the XLogRecord header,
37  * and also not any backup blocks.  xl_tot_len counts everything.  Neither
38  * length field is rounded up to an alignment boundary.
39  */
40 typedef struct XLogRecord
41 {
42         uint32          xl_tot_len;             /* total len of entire record */
43         TransactionId xl_xid;           /* xact id */
44         uint32          xl_len;                 /* total len of rmgr data */
45         uint8           xl_info;                /* flag bits, see below */
46         RmgrId          xl_rmid;                /* resource manager for this record */
47         /* 2 bytes of padding here, initialize to zero */
48         XLogRecPtr      xl_prev;                /* ptr to previous record in log */
49         pg_crc32        xl_crc;                 /* CRC for this record */
50
51         /* If MAXALIGN==8, there are 4 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 4 disk blocks per XLOG
69  * record.
70  */
71 #define XLR_BKP_BLOCK_MASK              0x0F    /* all info bits used for bkp blocks */
72 #define XLR_MAX_BKP_BLOCKS              4
73 #define XLR_BKP_BLOCK(iblk)             (0x08 >> (iblk))                /* iblk in 0..3 */
74
75 /*
76  * Header info for a backup block appended to an XLOG record.
77  *
78  * As a trivial form of data compression, the XLOG code is aware that
79  * PG data pages usually contain an unused "hole" in the middle, which
80  * contains only zero bytes.  If hole_length > 0 then we have removed
81  * such a "hole" from the stored data (and it's not counted in the
82  * XLOG record's CRC, either).  Hence, the amount of block data actually
83  * present following the BkpBlock struct is BLCKSZ - hole_length bytes.
84  *
85  * Note that we don't attempt to align either the BkpBlock struct or the
86  * block's data.  So, the struct must be copied to aligned local storage
87  * before use.
88  */
89 typedef struct BkpBlock
90 {
91         RelFileNode node;                       /* relation containing block */
92         ForkNumber      fork;                   /* fork within the relation */
93         BlockNumber block;                      /* block number */
94         uint16          hole_offset;    /* number of bytes before "hole" */
95         uint16          hole_length;    /* number of bytes in "hole" */
96
97         /* ACTUAL BLOCK DATA FOLLOWS AT END OF STRUCT */
98 } BkpBlock;
99
100 #endif   /* XLOGRECORD_H */