From 4f7b29176da82f2ecddddfaf2e865bfd82a86fad Mon Sep 17 00:00:00 2001 From: = Date: Tue, 18 Nov 2025 05:44:34 +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 d3a01c9eda7..4853823005c 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -58,6 +58,10 @@ #include "utils/builtins.h" #include "utils/guc_hooks.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. @@ -2182,6 +2186,12 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) slot->last_saved_confirmed_flush = cp.slotdata.confirmed_flush; 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 */ +