From 2e372c392105e709cca8d9224c9c0a1fa5bd3aff Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Thu, 1 Aug 2024 23:11:13 +0300 Subject: [PATCH] Supprot opaque mode for log_newpages --- src/backend/access/gist/gistbuild.c | 2 +- src/backend/access/transam/xloginsert.c | 11 +++++------ src/backend/access/transam/xlogutils.c | 2 +- src/include/access/xloginsert.h | 3 ++- src/include/access/xlogrecord.h | 7 ++++--- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c index b60cdbb627e..da73d51bf73 100644 --- a/src/backend/access/gist/gistbuild.c +++ b/src/backend/access/gist/gistbuild.c @@ -685,7 +685,7 @@ gist_indexsortbuild_flush_ready_pages(GISTBuildState *state) if (RelationNeedsWAL(state->indexrel)) log_newpages(&state->indexrel->rd_locator, MAIN_FORKNUM, state->ready_num_pages, - state->ready_blknos, state->ready_pages, true); + state->ready_blknos, state->ready_pages, REGBUF_STANDARD); for (int i = 0; i < state->ready_num_pages; i++) pfree(state->ready_pages[i]); diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index 1fc2159b193..1daf20c7359 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -638,6 +638,8 @@ XLogRecordAssemble(RmgrId rmid, uint8 info, if ((regbuf->flags & REGBUF_WILL_INIT) == REGBUF_WILL_INIT) bkpb.fork_flags |= BKPBLOCK_WILL_INIT; + if (regbuf->flags & REGBUF_OPAQUE) + bkpb.fork_flags |= BKPBLOCK_OPAQUE; /* * If needs_backup is true or WAL checking is enabled for current @@ -1186,16 +1188,13 @@ log_newpage(RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blkno, */ void log_newpages(RelFileLocator *rlocator, ForkNumber forknum, int num_pages, - BlockNumber *blknos, Page *pages, bool page_std) + BlockNumber *blknos, Page *pages, int flags) { - int flags; XLogRecPtr recptr; int i; int j; - flags = REGBUF_FORCE_IMAGE; - if (page_std) - flags |= REGBUF_STANDARD; + flags |= REGBUF_FORCE_IMAGE; /* * Iterate over all the pages. They are collected into batches of @@ -1228,7 +1227,7 @@ log_newpages(RelFileLocator *rlocator, ForkNumber forknum, int num_pages, * The page may be uninitialized. If so, we can't set the LSN * because that would corrupt the page. */ - if (!PageIsNew(pages[j])) + if (!(flags & REGBUF_OPAQUE) && !PageIsNew(pages[j])) { PageSetLSN(pages[j], recptr); } diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 68df6a3b56c..84dcd1ab412 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -418,7 +418,7 @@ XLogReadBufferForRedoExtended(XLogReaderState *record, * The page may be uninitialized. If so, we can't set the LSN because * that would corrupt the page. */ - if (!PageIsNew(page)) + if (!(XLogRecGetBlock(record, block_id)->flags & BKPBLOCK_OPAQUE) && !PageIsNew(page)) { PageSetLSN(page, lsn); } diff --git a/src/include/access/xloginsert.h b/src/include/access/xloginsert.h index e29c27345ce..77cbda97efe 100644 --- a/src/include/access/xloginsert.h +++ b/src/include/access/xloginsert.h @@ -37,6 +37,7 @@ * will be skipped) */ #define REGBUF_KEEP_DATA 0x10 /* include data even if a full-page image * is taken */ +#define REGBUF_OPAQUE 0x40 /* Do not interprete page header */ extern int max_replication_apply_lag; extern int max_replication_flush_lag; @@ -59,7 +60,7 @@ extern bool XLogCheckBufferNeedsBackup(Buffer buffer); extern XLogRecPtr log_newpage(RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blkno, char *page, bool page_std); extern void log_newpages(RelFileLocator *rlocator, ForkNumber forknum, int num_pages, - BlockNumber *blknos, char **pages, bool page_std); + BlockNumber *blknos, char **pages, int flags); extern XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std); extern void log_newpage_range(Relation rel, ForkNumber forknum, BlockNumber startblk, BlockNumber endblk, bool page_std); diff --git a/src/include/access/xlogrecord.h b/src/include/access/xlogrecord.h index f355e08e1d3..962fccd7176 100644 --- a/src/include/access/xlogrecord.h +++ b/src/include/access/xlogrecord.h @@ -190,11 +190,12 @@ typedef struct XLogRecordBlockCompressHeader sizeof(BlockNumber)) /* - * The fork number fits in the lower 4 bits in the fork_flags field. The upper + * The fork number fits in the lower 3 bits in the fork_flags field. The upper * bits are used for flags. */ -#define BKPBLOCK_FORK_MASK 0x0F -#define BKPBLOCK_FLAG_MASK 0xF0 +#define BKPBLOCK_FORK_MASK 0x07 +#define BKPBLOCK_FLAG_MASK 0xF8 +#define BKPBLOCK_OPAQUE 0x08 #define BKPBLOCK_HAS_IMAGE 0x10 /* block data is an XLogRecordBlockImage */ #define BKPBLOCK_HAS_DATA 0x20 #define BKPBLOCK_WILL_INIT 0x40 /* redo will re-init the page */