Skip to content

Commit a414705

Browse files
authored
[LKB-5974][PG_16]Add the ability to reduce FPI (#807)
# Context **Why is a full page image(FPI) unnecessary in Lakebase/Neon?** In vanilla PostgreSQL, full-page images (FPIs) are required to guard against torn page writes caused by non-atomic 8 KB page writes to local storage. However, in the Lakehouse/Neon architecture, FPIs are generally not needed because the compute node never overwrites pages in place. Instead, all modifications are logged as WAL records and sent to the pageserver, which appends them into the storage layer’s log-structured layout. Since there is no local data-file page overwriting, the torn-page risk that FPIs protect against does not exist on the compute node’s local storage. **Why do we want to reduce the full page image?** Full-page images amplify every small update into an 8 KB WAL write, which drives up WAL volume and causes Reverse ETL ingestion to hit the max_wal_rate limit in Serverless Lakebase. **Why not eliminate full-page images entirely?** Full-page images help the pageserver reduce read-path I/O by providing complete page snapshots that can be used during page reconstruction. Removing FPIs entirely could negatively impact read performance. # Summary This PR(along with the hadron PR: https://github.com/databricks-eng/hadron/pull/3155 )implements reducing FPI to improve write performance for data ingestion workloads, specifically reverse ETL and Spark streaming use cases. The feature is opt-in per table to avoid unintended impact on other customers. ## Performance Impact Testing shows 3.75x write throughput improvement without significantly impacting read performance. See [performance analysis. ](https://docs.google.com/document/d/19yY8nogB5hTjXmAsX-5GT4LVDNX3c86_gK2Y6Fu7TTw/edit?tab=t.quizviqwhqh0#heading=h.kw4pwpzifs9u) # Major changes ## Probabilistic reducing FPI generation to 5% Added `neon_should_suppress_fpi` which will randomly determine if we should suppress FPI with a default value of 5%. The 5% is chosen to: - Significantly reducing WAL volume to avoid write-amplification bottlenecks. - Retaining a small number of FPIs so the pageserver still benefits from occasional full-page snapshots, helping maintain efficient read-path performance.
1 parent b740647 commit a414705

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/backend/access/transam/xlog.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,10 @@ XLogInsertRecord(XLogRecData *rdata,
838838
* but not force a recomputation. (If doPageWrites was just turned off,
839839
* we could recompute the record without full pages, but we choose not to
840840
* bother.)
841+
*
842+
* However, if suppress_fpi is true, we skip the recomputation check
843+
* since we're deliberately suppressing full page images for this
844+
* record via the FPI control hook.
841845
*/
842846
if (RedoRecPtr != Insert->RedoRecPtr)
843847
{
@@ -848,7 +852,8 @@ XLogInsertRecord(XLogRecData *rdata,
848852

849853
if (doPageWrites &&
850854
(!prevDoPageWrites ||
851-
(fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr)))
855+
(!suppress_fpi &&
856+
fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr)))
852857
{
853858
/*
854859
* Oops, some buffer now needs to be backed up that the caller didn't

src/backend/access/transam/xloginsert.c

Lines changed: 22 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 determine if FPI should be suppressed for a WAL record */
98+
xlog_should_suppress_fpi_hook_type xlog_should_suppress_fpi_hook = NULL;
99+
100+
/* NEON: Global flag to suppress FPI for current WAL record */
101+
bool suppress_fpi = 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 suppress FPI for this WAL record.
527+
*/
528+
suppress_fpi = false;
529+
if (xlog_should_suppress_fpi_hook != NULL) {
530+
suppress_fpi = xlog_should_suppress_fpi_hook();
531+
elog(DEBUG1, "FPI suppress hook called: suppress_fpi=%d, doPageWrites=%d",
532+
suppress_fpi, doPageWrites);
533+
}
534+
519535
rdt = XLogRecordAssemble(rmid, info, RedoRecPtr, doPageWrites,
520536
&fpw_lsn, &num_fpi, &topxid_included);
521537

@@ -605,7 +621,7 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
605621
needs_backup = true;
606622
else if (regbuf->flags & REGBUF_NO_IMAGE)
607623
needs_backup = false;
608-
else if (!doPageWrites)
624+
else if (!doPageWrites || suppress_fpi)
609625
needs_backup = false;
610626
else
611627
{
@@ -617,8 +633,13 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
617633
XLogRecPtr page_lsn = PageGetLSN(regbuf->page);
618634

619635
needs_backup = (page_lsn <= RedoRecPtr);
636+
620637
if (!needs_backup)
621638
{
639+
/*
640+
* Set fpw_lsn to signal that this record should be
641+
* recomputed if doPageWrites changes.
642+
*/
622643
if (*fpw_lsn == InvalidXLogRecPtr || page_lsn < *fpw_lsn)
623644
*fpw_lsn = page_lsn;
624645
}

src/include/access/xloginsert.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ 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 determine if FPI should be suppressed for a WAL record
46+
* Returns true to suppress FPI, false to allow FPI
47+
* Applies to all resource managers for checkpoint-based FPI triggers.
48+
*/
49+
typedef bool (*xlog_should_suppress_fpi_hook_type)(void);
50+
extern PGDLLIMPORT xlog_should_suppress_fpi_hook_type xlog_should_suppress_fpi_hook;
51+
52+
/* NEON: Flag set per-record to suppress FPI (set by xlog_should_suppress_fpi_hook) */
53+
extern bool suppress_fpi;
54+
4555
/* prototypes for public functions in xloginsert.c: */
4656
extern void XLogBeginInsert(void);
4757
extern void XLogSetRecordFlags(uint8 flags);

0 commit comments

Comments
 (0)