Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8cb23db

Browse files
committed
Properly re-initialize replication slot shared memory upon creation.
Slot creation did not clear all fields upon creation. After start the memory is zeroed, but when a physical replication slot was created in the shared memory of a previously existing logical slot, catalog_xmin would not be cleared. That in turn would prevent vacuum from doing its duties. To fix initialize all the fields. To make similar future bugs less likely, zero all of ReplicationSlotPersistentData, and re-order the rest of the initialization to be in struct member order. Analysis: Andrew Gierth Reported-By: md@chewy.com Author: Michael Paquier Discussion: <20160705173502.1398.70934@wrigleys.postgresql.org> Backpatch: 9.4, where replication slots were introduced
1 parent d715b76 commit 8cb23db

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/backend/replication/slot.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,22 @@ ReplicationSlotCreate(const char *name, bool db_specific,
272272
*/
273273
Assert(!slot->in_use);
274274
Assert(slot->active_pid == 0);
275-
slot->data.persistency = persistency;
276-
slot->data.xmin = InvalidTransactionId;
277-
slot->effective_xmin = InvalidTransactionId;
275+
276+
/* first initialize persistent data */
277+
memset(&slot->data, 0, sizeof(ReplicationSlotPersistentData));
278278
StrNCpy(NameStr(slot->data.name), name, NAMEDATALEN);
279279
slot->data.database = db_specific ? MyDatabaseId : InvalidOid;
280-
slot->data.restart_lsn = InvalidXLogRecPtr;
280+
slot->data.persistency = persistency;
281+
282+
/* and then data only present in shared memory */
283+
slot->just_dirtied = false;
284+
slot->dirty = false;
285+
slot->effective_xmin = InvalidTransactionId;
286+
slot->effective_catalog_xmin = InvalidTransactionId;
287+
slot->candidate_catalog_xmin = InvalidTransactionId;
288+
slot->candidate_xmin_lsn = InvalidXLogRecPtr;
289+
slot->candidate_restart_valid = InvalidXLogRecPtr;
290+
slot->candidate_restart_lsn = InvalidXLogRecPtr;
281291

282292
/*
283293
* Create the slot on disk. We haven't actually marked the slot allocated

0 commit comments

Comments
 (0)