From 8261b8652ca8cbbe31e5dd490fc4d2aa1f5e1da4 Mon Sep 17 00:00:00 2001 From: Nolan Biscaro Date: Tue, 2 Dec 2025 23:49:41 +0000 Subject: [PATCH] add logical slot persistence hooks --- src/backend/replication/slot.c | 10 ++++++++ src/include/replication/logical_slots_store.h | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/include/replication/logical_slots_store.h diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index eb030863f8d..1b4bd4429c9 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -59,6 +59,10 @@ #include "utils/guc_hooks.h" #include "utils/injection_point.h" #include "utils/varlena.h" +#include "replication/logical_slots_store.h" + +/* NEON: Hook for storing logical slot state - implemented by neon extension */ +logical_slots_store_hook_type logical_slots_store_hook = NULL; /* * Replication slot on-disk data structure. @@ -2450,6 +2454,12 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) slot->last_saved_restart_lsn = cp.slotdata.restart_lsn; SpinLockRelease(&slot->mutex); + /* + * NEON: Store to external storage while holding io_in_progress_lock. + */ + if (logical_slots_store_hook != NULL) + logical_slots_store_hook(dir, &cp.slotdata); + LWLockRelease(&slot->io_in_progress_lock); } diff --git a/src/include/replication/logical_slots_store.h b/src/include/replication/logical_slots_store.h new file mode 100644 index 00000000000..172096ab304 --- /dev/null +++ b/src/include/replication/logical_slots_store.h @@ -0,0 +1,24 @@ +/*------------------------------------------------------------------------- + * + * logical_slots_store.h + * Logical replication slot state persistence + * + * IDENTIFICATION + * src/include/replication/logical_slots_store.h + * + *------------------------------------------------------------------------- + */ +#ifndef LOGICAL_SLOTS_STORE_H +#define LOGICAL_SLOTS_STORE_H + +#include "replication/slot.h" + +/* Hook for storing logical slot state */ +typedef void (*logical_slots_store_hook_type) (const char *dir, ReplicationSlotPersistentData *saved_data); +extern PGDLLIMPORT logical_slots_store_hook_type logical_slots_store_hook; + +/* Extension function - called by the hook */ +extern void store_logical_slots_state(const char *dir, ReplicationSlotPersistentData *saved_data); + +#endif /* LOGICAL_SLOTS_STORE_H */ +