]> granicus.if.org Git - postgresql/blobdiff - src/include/access/xlogrecord.h
Update copyright for 2016
[postgresql] / src / include / access / xlogrecord.h
index 25a92657b852859e8f78c057640131cbeb21e569..3dfcb494f7c4105d22faccaede6248dfb77d3a7d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Definitions for the WAL record format.
  *
- * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/access/xlogrecord.h
@@ -13,7 +13,7 @@
 
 #include "access/rmgr.h"
 #include "access/xlogdefs.h"
-#include "common/pg_crc.h"
+#include "port/pg_crc32c.h"
 #include "storage/block.h"
 #include "storage/relfilenode.h"
 
@@ -46,13 +46,13 @@ typedef struct XLogRecord
        uint8           xl_info;                /* flag bits, see below */
        RmgrId          xl_rmid;                /* resource manager for this record */
        /* 2 bytes of padding here, initialize to zero */
-       pg_crc32        xl_crc;                 /* CRC for this record */
+       pg_crc32c       xl_crc;                 /* CRC for this record */
 
        /* XLogRecordBlockHeaders and XLogRecordDataHeader follow, no padding */
 
 } XLogRecord;
 
-#define SizeOfXLogRecord       (offsetof(XLogRecord, xl_crc) + sizeof(pg_crc32))
+#define SizeOfXLogRecord       (offsetof(XLogRecord, xl_crc) + sizeof(pg_crc32c))
 
 /*
  * The high 4 bits in xl_info may be used freely by rmgr. The
@@ -88,7 +88,7 @@ typedef struct XLogRecordBlockHeader
                                                                 * image) */
 
        /* If BKPBLOCK_HAS_IMAGE, an XLogRecordBlockImageHeader struct follows */
-       /* If !BKPBLOCK_SAME_REL is not set, a RelFileNode follows */
+       /* If BKPBLOCK_SAME_REL is not set, a RelFileNode follows */
        /* BlockNumber follows */
 } XLogRecordBlockHeader;
 
@@ -100,18 +100,55 @@ typedef struct XLogRecordBlockHeader
  *
  * As a trivial form of data compression, the XLOG code is aware that
  * PG data pages usually contain an unused "hole" in the middle, which
- * contains only zero bytes.  If hole_length > 0 then we have removed
+ * contains only zero bytes.  If the length of "hole" > 0 then we have removed
  * such a "hole" from the stored data (and it's not counted in the
  * XLOG record's CRC, either).  Hence, the amount of block data actually
- * present is BLCKSZ - hole_length bytes.
+ * present is BLCKSZ - the length of "hole" bytes.
+ *
+ * When wal_compression is enabled, a full page image which "hole" was
+ * removed is additionally compressed using PGLZ compression algorithm.
+ * This can reduce the WAL volume, but at some extra cost of CPU spent
+ * on the compression during WAL logging. In this case, since the "hole"
+ * length cannot be calculated by subtracting the number of page image bytes
+ * from BLCKSZ, basically it needs to be stored as an extra information.
+ * But when no "hole" exists, we can assume that the "hole" length is zero
+ * and no such an extra information needs to be stored. Note that
+ * the original version of page image is stored in WAL instead of the
+ * compressed one if the number of bytes saved by compression is less than
+ * the length of extra information. Hence, when a page image is successfully
+ * compressed, the amount of block data actually present is less than
+ * BLCKSZ - the length of "hole" bytes - the length of extra information.
  */
 typedef struct XLogRecordBlockImageHeader
 {
+       uint16          length;                 /* number of page image bytes */
        uint16          hole_offset;    /* number of bytes before "hole" */
-       uint16          hole_length;    /* number of bytes in "hole" */
+       uint8           bimg_info;              /* flag bits, see below */
+
+       /*
+        * If BKPIMAGE_HAS_HOLE and BKPIMAGE_IS_COMPRESSED, an
+        * XLogRecordBlockCompressHeader struct follows.
+        */
 } XLogRecordBlockImageHeader;
 
-#define SizeOfXLogRecordBlockImageHeader sizeof(XLogRecordBlockImageHeader)
+#define SizeOfXLogRecordBlockImageHeader       \
+       (offsetof(XLogRecordBlockImageHeader, bimg_info) + sizeof(uint8))
+
+/* Information stored in bimg_info */
+#define BKPIMAGE_HAS_HOLE              0x01    /* page image has "hole" */
+#define BKPIMAGE_IS_COMPRESSED         0x02            /* page image is compressed */
+
+/*
+ * Extra header information used when page image has "hole" and
+ * is compressed.
+ */
+typedef struct XLogRecordBlockCompressHeader
+{
+       uint16          hole_length;    /* number of bytes in "hole" */
+} XLogRecordBlockCompressHeader;
+
+#define SizeOfXLogRecordBlockCompressHeader \
+       sizeof(XLogRecordBlockCompressHeader)
 
 /*
  * Maximum size of the header for a block reference. This is used to size a
@@ -120,6 +157,7 @@ typedef struct XLogRecordBlockImageHeader
 #define MaxSizeOfXLogRecordBlockHeader \
        (SizeOfXLogRecordBlockHeader + \
         SizeOfXLogRecordBlockImageHeader + \
+        SizeOfXLogRecordBlockCompressHeader + \
         sizeof(RelFileNode) + \
         sizeof(BlockNumber))
 
@@ -147,7 +185,7 @@ typedef struct XLogRecordDataHeaderShort
 {
        uint8           id;                             /* XLR_BLOCK_ID_DATA_SHORT */
        uint8           data_length;    /* number of payload bytes */
-} XLogRecordDataHeaderShort;
+}      XLogRecordDataHeaderShort;
 
 #define SizeOfXLogRecordDataHeaderShort (sizeof(uint8) * 2)
 
@@ -155,7 +193,7 @@ typedef struct XLogRecordDataHeaderLong
 {
        uint8           id;                             /* XLR_BLOCK_ID_DATA_LONG */
        /* followed by uint32 data_length, unaligned */
-} XLogRecordDataHeaderLong;
+}      XLogRecordDataHeaderLong;
 
 #define SizeOfXLogRecordDataHeaderLong (sizeof(uint8) + sizeof(uint32))
 
@@ -174,5 +212,6 @@ typedef struct XLogRecordDataHeaderLong
 
 #define XLR_BLOCK_ID_DATA_SHORT                255
 #define XLR_BLOCK_ID_DATA_LONG         254
+#define XLR_BLOCK_ID_ORIGIN                    253
 
 #endif   /* XLOGRECORD_H */