Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support opaque mode for log_newpages #456

Open
wants to merge 1 commit into
base: REL_16_STABLE_neon
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/access/gist/gistbuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
11 changes: 5 additions & 6 deletions src/backend/access/transam/xloginsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/access/transam/xlogutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/include/access/xloginsert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/include/access/xlogrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down