Skip to content

Commit bfd5776

Browse files
committed
[LKB-5974][PG_16]Add the ability to reduce FPI
1 parent 0374078 commit bfd5776

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/backend/access/transam/xlog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,8 @@ XLogInsertRecord(XLogRecData *rdata,
848848

849849
if (doPageWrites &&
850850
(!prevDoPageWrites ||
851-
(fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr)))
851+
(!force_disable_full_page_write &&
852+
fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr)))
852853
{
853854
/*
854855
* Oops, some buffer now needs to be backed up that the caller didn't

src/backend/access/transam/xloginsert.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ int max_replication_apply_lag;
9494
int max_replication_flush_lag;
9595
int max_replication_write_lag;
9696

97+
/* NEON: Hook to control Full Page Image (FPI) writes */
98+
xlog_fpi_control_hook_type xlog_fpi_control_hook = NULL;
99+
100+
/* NEON: Global flag to force disable FPI for current WAL record */
101+
bool force_disable_full_page_write = false;
102+
97103
static registered_buffer *registered_buffers;
98104
static int max_registered_buffers; /* allocated size */
99105
static int max_registered_block_id = 0; /* highest block_id + 1 currently
@@ -516,6 +522,16 @@ XLogInsert(RmgrId rmid, uint8 info)
516522
*/
517523
GetFullPageWriteInfo(&RedoRecPtr, &doPageWrites);
518524

525+
/*
526+
* NEON: Check if we should force disable FPI for this WAL record.
527+
*/
528+
force_disable_full_page_write = false;
529+
if (xlog_fpi_control_hook != NULL) {
530+
force_disable_full_page_write = xlog_fpi_control_hook(rmid);
531+
elog(DEBUG1, "FPI control hook called: rmid=%u, force_disable=%d, doPageWrites=%d",
532+
rmid, force_disable_full_page_write, doPageWrites);
533+
}
534+
519535
rdt = XLogRecordAssemble(rmid, info, RedoRecPtr, doPageWrites,
520536
&fpw_lsn, &num_fpi, &topxid_included);
521537

@@ -616,9 +632,17 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
616632
*/
617633
XLogRecPtr page_lsn = PageGetLSN(regbuf->page);
618634

619-
needs_backup = (page_lsn <= RedoRecPtr);
635+
if (force_disable_full_page_write)
636+
needs_backup = false;
637+
else
638+
needs_backup = (page_lsn <= RedoRecPtr);
639+
620640
if (!needs_backup)
621641
{
642+
/*
643+
* Set fpw_lsn to signal that this record should be
644+
* recomputed if doPageWrites changes.
645+
*/
622646
if (*fpw_lsn == InvalidXLogRecPtr || page_lsn < *fpw_lsn)
623647
*fpw_lsn = page_lsn;
624648
}

src/include/access/xloginsert.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ extern int max_replication_apply_lag;
4242
extern int max_replication_flush_lag;
4343
extern int max_replication_write_lag;
4444

45+
/* NEON: Hook to control Full Page Image (FPI) writes
46+
* Returns true to DISABLE FPI, false to keep FPI enabled
47+
* Parameters:
48+
* rmid - Resource manager ID (e.g., RM_HEAP_ID, RM_BTREE_ID)
49+
*/
50+
typedef bool (*xlog_fpi_control_hook_type)(RmgrId rmid);
51+
extern PGDLLIMPORT xlog_fpi_control_hook_type xlog_fpi_control_hook;
52+
53+
/* NEON: Flag set per-record to force disable FPI (set by neon_should_disable_fpi hook) */
54+
extern bool force_disable_full_page_write;
55+
4556
/* prototypes for public functions in xloginsert.c: */
4657
extern void XLogBeginInsert(void);
4758
extern void XLogSetRecordFlags(uint8 flags);

0 commit comments

Comments
 (0)