diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-11-20 17:56:26 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-11-20 18:46:41 +0200 |
commit | 2c03216d831160bedd72d45f712601b6f7d03f1c (patch) | |
tree | ab6a03d031ffa605d848b0b7067add15e56e2207 /src/backend/access/rmgrdesc/gindesc.c | |
parent | 8dc626defec23016dd5988208d8704b858b9d21d (diff) | |
download | postgresql-2c03216d831160bedd72d45f712601b6f7d03f1c.tar.gz postgresql-2c03216d831160bedd72d45f712601b6f7d03f1c.zip |
Revamp the WAL record format.
Each WAL record now carries information about the modified relation and
block(s) in a standardized format. That makes it easier to write tools that
need that information, like pg_rewind, prefetching the blocks to speed up
recovery, etc.
There's a whole new API for building WAL records, replacing the XLogRecData
chains used previously. The new API consists of XLogRegister* functions,
which are called for each buffer and chunk of data that is added to the
record. The new API also gives more control over when a full-page image is
written, by passing flags to the XLogRegisterBuffer function.
This also simplifies the XLogReadBufferForRedo() calls. The function can dig
the relation and block number from the WAL record, so they no longer need to
be passed as arguments.
For the convenience of redo routines, XLogReader now disects each WAL record
after reading it, copying the main data part and the per-block data into
MAXALIGNed buffers. The data chunks are not aligned within the WAL record,
but the redo routines can assume that the pointers returned by XLogRecGet*
functions are. Redo routines are now passed the XLogReaderState, which
contains the record in the already-disected format, instead of the plain
XLogRecord.
The new record format also makes the fixed size XLogRecord header smaller,
by removing the xl_len field. The length of the "main data" portion is now
stored at the end of the WAL record, and there's a separate header after
XLogRecord for it. The alignment padding at the end of XLogRecord is also
removed. This compansates for the fact that the new format would otherwise
be more bulky than the old format.
Reviewed by Andres Freund, Amit Kapila, Michael Paquier, Alvaro Herrera,
Fujii Masao.
Diffstat (limited to 'src/backend/access/rmgrdesc/gindesc.c')
-rw-r--r-- | src/backend/access/rmgrdesc/gindesc.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/backend/access/rmgrdesc/gindesc.c b/src/backend/access/rmgrdesc/gindesc.c index 2f783cee2bb..8754214f644 100644 --- a/src/backend/access/rmgrdesc/gindesc.c +++ b/src/backend/access/rmgrdesc/gindesc.c @@ -15,17 +15,11 @@ #include "postgres.h" #include "access/gin_private.h" +#include "access/xlogutils.h" #include "lib/stringinfo.h" #include "storage/relfilenode.h" static void -desc_node(StringInfo buf, RelFileNode node, BlockNumber blkno) -{ - appendStringInfo(buf, "node: %u/%u/%u blkno: %u", - node.spcNode, node.dbNode, node.relNode, blkno); -} - -static void desc_recompress_leaf(StringInfo buf, ginxlogRecompressDataLeaf *insertData) { int i; @@ -77,26 +71,25 @@ desc_recompress_leaf(StringInfo buf, ginxlogRecompressDataLeaf *insertData) } void -gin_desc(StringInfo buf, XLogRecord *record) +gin_desc(StringInfo buf, XLogReaderState *record) { char *rec = XLogRecGetData(record); - uint8 info = record->xl_info & ~XLR_INFO_MASK; + uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; switch (info) { case XLOG_GIN_CREATE_INDEX: - desc_node(buf, *(RelFileNode *) rec, GIN_ROOT_BLKNO); + /* no further information */ break; case XLOG_GIN_CREATE_PTREE: - desc_node(buf, ((ginxlogCreatePostingTree *) rec)->node, ((ginxlogCreatePostingTree *) rec)->blkno); + /* no further information */ break; case XLOG_GIN_INSERT: { ginxlogInsert *xlrec = (ginxlogInsert *) rec; char *payload = rec + sizeof(ginxlogInsert); - desc_node(buf, xlrec->node, xlrec->blkno); - appendStringInfo(buf, " isdata: %c isleaf: %c", + appendStringInfo(buf, "isdata: %c isleaf: %c", (xlrec->flags & GIN_INSERT_ISDATA) ? 'T' : 'F', (xlrec->flags & GIN_INSERT_ISLEAF) ? 'T' : 'F'); if (!(xlrec->flags & GIN_INSERT_ISLEAF)) @@ -119,7 +112,7 @@ gin_desc(StringInfo buf, XLogRecord *record) ginxlogRecompressDataLeaf *insertData = (ginxlogRecompressDataLeaf *) payload; - if (record->xl_info & XLR_BKP_BLOCK(0)) + if (XLogRecHasBlockImage(record, 0)) appendStringInfo(buf, " (full page image)"); else desc_recompress_leaf(buf, insertData); @@ -139,39 +132,38 @@ gin_desc(StringInfo buf, XLogRecord *record) { ginxlogSplit *xlrec = (ginxlogSplit *) rec; - desc_node(buf, ((ginxlogSplit *) rec)->node, ((ginxlogSplit *) rec)->lblkno); - appendStringInfo(buf, " isrootsplit: %c", (((ginxlogSplit *) rec)->flags & GIN_SPLIT_ROOT) ? 'T' : 'F'); + appendStringInfo(buf, "isrootsplit: %c", + (((ginxlogSplit *) rec)->flags & GIN_SPLIT_ROOT) ? 'T' : 'F'); appendStringInfo(buf, " isdata: %c isleaf: %c", (xlrec->flags & GIN_INSERT_ISDATA) ? 'T' : 'F', (xlrec->flags & GIN_INSERT_ISLEAF) ? 'T' : 'F'); } break; case XLOG_GIN_VACUUM_PAGE: - desc_node(buf, ((ginxlogVacuumPage *) rec)->node, ((ginxlogVacuumPage *) rec)->blkno); + /* no further information */ break; case XLOG_GIN_VACUUM_DATA_LEAF_PAGE: { ginxlogVacuumDataLeafPage *xlrec = (ginxlogVacuumDataLeafPage *) rec; - desc_node(buf, xlrec->node, xlrec->blkno); - if (record->xl_info & XLR_BKP_BLOCK(0)) + if (XLogRecHasBlockImage(record, 0)) appendStringInfo(buf, " (full page image)"); else desc_recompress_leaf(buf, &xlrec->data); } break; case XLOG_GIN_DELETE_PAGE: - desc_node(buf, ((ginxlogDeletePage *) rec)->node, ((ginxlogDeletePage *) rec)->blkno); + /* no further information */ break; case XLOG_GIN_UPDATE_META_PAGE: - desc_node(buf, ((ginxlogUpdateMeta *) rec)->node, GIN_METAPAGE_BLKNO); + /* no further information */ break; case XLOG_GIN_INSERT_LISTPAGE: - desc_node(buf, ((ginxlogInsertListPage *) rec)->node, ((ginxlogInsertListPage *) rec)->blkno); + /* no further information */ break; case XLOG_GIN_DELETE_LISTPAGE: - appendStringInfo(buf, "%d pages, ", ((ginxlogDeleteListPages *) rec)->ndeleted); - desc_node(buf, ((ginxlogDeleteListPages *) rec)->node, GIN_METAPAGE_BLKNO); + appendStringInfo(buf, "ndeleted: %d", + ((ginxlogDeleteListPages *) rec)->ndeleted); break; } } |