Skip to content

Commit c1a7abd

Browse files
author
Antonin Houska
committed
Double-check replication slot's effective_xmin before use.
Paranoia. Also move related code in create_replication_slots() to more suitable place.
1 parent 8791c89 commit c1a7abd

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pg_squeeze.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,15 @@ setup_decoding(Oid relid, TupleDesc tup_desc, Snapshot *snap_hist)
970970
*/
971971
ReplicationSlotAcquire(NameStr(repl_slot->name), true);
972972

973+
/*
974+
* This should not really happen, but if it did, the initial load could
975+
* miss some data.
976+
*/
977+
if (!TransactionIdIsValid(MyReplicationSlot->effective_xmin))
978+
ereport(ERROR,
979+
(errmsg("replication slot \"%s\" has invalid effective_xmin",
980+
NameStr(repl_slot->name))));
981+
973982
/*
974983
* It's pretty unlikely for some client to have consumed data changes
975984
* (accidentally?) before this worker could acquire the slot, but it's

worker.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,13 +1598,6 @@ create_replication_slots(int nslots, MemoryContext mcxt)
15981598
*/
15991599
Assert(!ctx->fast_forward);
16001600

1601-
SpinLockAcquire(&slot->mutex);
1602-
Assert(TransactionIdIsValid(slot->effective_xmin) &&
1603-
!TransactionIdIsValid(slot->data.xmin));
1604-
/* Prevent ReplicationSlotRelease() from clearing effective_xmin. */
1605-
slot->data.xmin = slot->effective_xmin;
1606-
SpinLockRelease(&slot->mutex);
1607-
16081601
/*
16091602
* Bring the snapshot builder into the SNAPBUILD_CONSISTENT state so
16101603
* that the worker can get its snapshot and start decoding
@@ -1654,6 +1647,14 @@ create_replication_slots(int nslots, MemoryContext mcxt)
16541647
* Done for now, the worker will have to setup the context on its own.
16551648
*/
16561649
FreeDecodingContext(ctx);
1650+
1651+
/* Prevent ReplicationSlotRelease() from clearing effective_xmin. */
1652+
SpinLockAcquire(&slot->mutex);
1653+
Assert(TransactionIdIsValid(slot->effective_xmin) &&
1654+
!TransactionIdIsValid(slot->data.xmin));
1655+
slot->data.xmin = slot->effective_xmin;
1656+
SpinLockRelease(&slot->mutex);
1657+
16571658
ReplicationSlotRelease();
16581659
}
16591660

0 commit comments

Comments
 (0)