Skip to content

Commit 670cc02

Browse files
alterego655hackorum
authored andcommitted
Use outer memory context across slot sync retries
Capture the outer memory context once before the retry loop in SyncReplicationSlots() to better better matches the actual lifetime model: sync_retry_ctx is the per-cycle child context, while slot_names must live in the parent/outer context across resets. Rename the oldctx to outerctx to express the parent/child relationship more clearly.
1 parent 91f7521 commit 670cc02

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎src/backend/replication/logical/slotsync.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,17 +2085,20 @@ SyncReplicationSlots(WalReceiverConn *wrconn)
20852085
List *remote_slots = NIL;
20862086
List *slot_names = NIL; /* List of slot names to track */
20872087
MemoryContext sync_retry_ctx;
2088+
MemoryContext outerctx;
20882089

20892090
check_and_set_sync_info(MyProcPid);
20902091

20912092
validate_remote_info(wrconn);
20922093

2094+
outerctx = CurrentMemoryContext;
2095+
20932096
/*
20942097
* Setup and use a per-sync-cycle memory context, which is reset every
20952098
* time we loop below. This avoids having to retail freeing the memory
20962099
* used in each sync cycle.
20972100
*/
2098-
sync_retry_ctx = AllocSetContextCreate(CurrentMemoryContext,
2101+
sync_retry_ctx = AllocSetContextCreate(outerctx,
20992102
"slot sync retry context",
21002103
ALLOCSET_DEFAULT_SIZES);
21012104

@@ -2104,7 +2107,6 @@ SyncReplicationSlots(WalReceiverConn *wrconn)
21042107
{
21052108
bool slot_persistence_pending = false;
21062109
bool some_slot_updated = false;
2107-
MemoryContext oldctx;
21082110

21092111
/* Check for interrupts and config changes */
21102112
CHECK_FOR_INTERRUPTS();
@@ -2116,7 +2118,7 @@ SyncReplicationSlots(WalReceiverConn *wrconn)
21162118
Assert(IsTransactionState());
21172119

21182120
MemoryContextReset(sync_retry_ctx);
2119-
oldctx = MemoryContextSwitchTo(sync_retry_ctx);
2121+
MemoryContextSwitchTo(sync_retry_ctx);
21202122

21212123
/*
21222124
* Fetch remote slot info for the given slot_names. If slot_names
@@ -2138,7 +2140,7 @@ SyncReplicationSlots(WalReceiverConn *wrconn)
21382140
* slot_names must survive later sync_retry_ctx resets, so copy it
21392141
* in the outer context.
21402142
*/
2141-
MemoryContextSwitchTo(oldctx);
2143+
MemoryContextSwitchTo(outerctx);
21422144

21432145
/*
21442146
* If slot_persistence_pending is true, extract slot names for

0 commit comments

Comments
 (0)