From c7011f95a998110b55adf404f1f0c8f6a45e99b5 Mon Sep 17 00:00:00 2001 From: Sasha Krassovsky Date: Mon, 12 Aug 2024 12:23:51 -0700 Subject: [PATCH] Add on-demand WAL download to slotfuncs --- src/backend/replication/slotfuncs.c | 14 +++++++++++--- src/include/replication/slot.h | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c index 16a35279037..22ee9761025 100644 --- a/src/backend/replication/slotfuncs.c +++ b/src/backend/replication/slotfuncs.c @@ -26,6 +26,8 @@ #include "utils/pg_lsn.h" #include "utils/resowner.h" +void (*SlotFuncs_Custom_XLogReaderRoutines)(XLogReaderRoutine *xlr); + /* * Helper function for creating a new physical replication slot with * given arguments. Note that this function doesn't release the created @@ -469,6 +471,14 @@ pg_logical_replication_slot_advance(XLogRecPtr moveto) PG_TRY(); { + XLogReaderRoutine xlr; + xlr.page_read = read_local_xlog_page; + xlr.segment_open = wal_segment_open; + xlr.segment_close = wal_segment_close; + + if (SlotFuncs_Custom_XLogReaderRoutines != NULL) + SlotFuncs_Custom_XLogReaderRoutines(&xlr); + /* * Create our decoding context in fast_forward mode, passing start_lsn * as InvalidXLogRecPtr, so that we start processing from my slot's @@ -477,9 +487,7 @@ pg_logical_replication_slot_advance(XLogRecPtr moveto) ctx = CreateDecodingContext(InvalidXLogRecPtr, NIL, true, /* fast_forward */ - XL_ROUTINE(.page_read = read_local_xlog_page, - .segment_open = wal_segment_open, - .segment_close = wal_segment_close), + &xlr, NULL, NULL, NULL); /* diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h index deba2c4e499..978b2d51f38 100644 --- a/src/include/replication/slot.h +++ b/src/include/replication/slot.h @@ -168,6 +168,8 @@ typedef struct ReplicationSlot #define SlotIsPhysical(slot) ((slot)->data.database == InvalidOid) #define SlotIsLogical(slot) ((slot)->data.database != InvalidOid) +extern void (*SlotFuncs_Custom_XLogReaderRoutines)(XLogReaderRoutine *xlr); + /* * Shared memory control area for all of replication slots. */