mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Change CRCs in WAL records from 64bit to 32bit for performance reasons.
Instead of a separate CRC on each backup block, include backup blocks in their parent WAL record's CRC; this is important to ensure that the backup block really goes with the WAL record, ie there was not a page tear right at the start of the backup block. Implement a simple form of compression of backup blocks: drop any run of zeroes starting at pd_lower, so as not to store the unused 'hole' that commonly exists in PG heap and index pages. Tweak PageRepairFragmentation and related routines to ensure they keep the unused space zeroed, so that the above compression method remains effective. All per recent discussions.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.61 2005/05/20 14:53:26 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.62 2005/06/02 05:55:29 tgl Exp $
|
||||
*/
|
||||
#ifndef XLOG_H
|
||||
#define XLOG_H
|
||||
@@ -19,23 +19,31 @@
|
||||
|
||||
|
||||
/*
|
||||
* Header for each record in XLOG
|
||||
* The overall layout of an XLOG record is:
|
||||
* Fixed-size header (XLogRecord struct)
|
||||
* rmgr-specific data
|
||||
* BkpBlock
|
||||
* backup block data
|
||||
* BkpBlock
|
||||
* backup block data
|
||||
* ...
|
||||
*
|
||||
* where there can be zero to three backup blocks (as signaled by xl_info flag
|
||||
* bits). XLogRecord structs always start on MAXALIGN boundaries in the WAL
|
||||
* files, and we round up SizeOfXLogRecord so that the rmgr data is also
|
||||
* guaranteed to begin on a MAXALIGN boundary. However, no padding is added
|
||||
* to align BkpBlock structs or backup block data.
|
||||
*
|
||||
* NOTE: xl_len counts only the rmgr data, not the XLogRecord header,
|
||||
* and also not any backup blocks appended to the record (which are signaled
|
||||
* by xl_info flag bits). The total space needed for an XLOG record is
|
||||
* really:
|
||||
*
|
||||
* SizeOfXLogRecord + xl_len + n_backup_blocks * (sizeof(BkpBlock) + BLCKSZ)
|
||||
*
|
||||
* rounded up to a MAXALIGN boundary (so that all xlog records start on
|
||||
* MAXALIGN boundaries).
|
||||
* and also not any backup blocks. xl_tot_len counts everything. Neither
|
||||
* length field is rounded up to an alignment boundary.
|
||||
*/
|
||||
typedef struct XLogRecord
|
||||
{
|
||||
crc64 xl_crc; /* CRC for this record */
|
||||
pg_crc32 xl_crc; /* CRC for this record */
|
||||
XLogRecPtr xl_prev; /* ptr to previous record in log */
|
||||
TransactionId xl_xid; /* xact id */
|
||||
uint32 xl_tot_len; /* total len of entire record */
|
||||
uint32 xl_len; /* total len of rmgr data */
|
||||
uint8 xl_info; /* flag bits, see below */
|
||||
RmgrId xl_rmid; /* resource manager for this record */
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.6 2004/12/31 22:03:21 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.7 2005/06/02 05:55:29 tgl Exp $
|
||||
*/
|
||||
#ifndef XLOG_INTERNAL_H
|
||||
#define XLOG_INTERNAL_H
|
||||
@@ -25,15 +25,25 @@
|
||||
/*
|
||||
* Header info for a backup block appended to an XLOG record.
|
||||
*
|
||||
* Note that the backup block has its own CRC, and is not covered by
|
||||
* the CRC of the XLOG record proper. Also note that we don't attempt
|
||||
* to align either the BkpBlock struct or the block's data.
|
||||
* 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
|
||||
* 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 following the BkpBlock struct is BLCKSZ - hole_length bytes.
|
||||
*
|
||||
* Note that we don't attempt to align either the BkpBlock struct or the
|
||||
* block's data. So, the struct must be copied to aligned local storage
|
||||
* before use.
|
||||
*/
|
||||
typedef struct BkpBlock
|
||||
{
|
||||
crc64 crc;
|
||||
RelFileNode node;
|
||||
BlockNumber block;
|
||||
RelFileNode node; /* relation containing block */
|
||||
BlockNumber block; /* block number */
|
||||
uint16 hole_offset; /* number of bytes before "hole" */
|
||||
uint16 hole_length; /* number of bytes in "hole" */
|
||||
|
||||
/* ACTUAL BLOCK DATA FOLLOWS AT END OF STRUCT */
|
||||
} BkpBlock;
|
||||
|
||||
/*
|
||||
@@ -42,8 +52,9 @@ typedef struct BkpBlock
|
||||
* XLogRecord header will never be split across pages; if there's less than
|
||||
* SizeOfXLogRecord space left at the end of a page, we just waste it.)
|
||||
*
|
||||
* Note that xl_rem_len includes backup-block data, unlike xl_len in the
|
||||
* initial header.
|
||||
* Note that xl_rem_len includes backup-block data; that is, it tracks
|
||||
* xl_tot_len not xl_len in the initial header. Also note that the
|
||||
* continuation data isn't necessarily aligned.
|
||||
*/
|
||||
typedef struct XLogContRecord
|
||||
{
|
||||
@@ -53,12 +64,12 @@ typedef struct XLogContRecord
|
||||
|
||||
} XLogContRecord;
|
||||
|
||||
#define SizeOfXLogContRecord MAXALIGN(sizeof(XLogContRecord))
|
||||
#define SizeOfXLogContRecord sizeof(XLogContRecord)
|
||||
|
||||
/*
|
||||
* Each page of XLOG file has a header like this:
|
||||
*/
|
||||
#define XLOG_PAGE_MAGIC 0xD05C /* can be used as WAL version indicator */
|
||||
#define XLOG_PAGE_MAGIC 0xD05D /* can be used as WAL version indicator */
|
||||
|
||||
typedef struct XLogPageHeaderData
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user