summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2023-01-12 04:40:33 +0000
committerMichael Paquier2023-01-12 04:40:33 +0000
commit5ad165d2c024ae2fdc0a5ddd17522d5c92d7aa1a (patch)
treeec7f55227255fa82fdd9b51fc912ac9e7228609d
parentf0e6d6d3c909e14eedd370dd77d7111c2ae24c02 (diff)
Acquire spinlock when updating 2PC slot data during logical decoding creation
The creation of a logical decoding context in CreateDecodingContext() updates some data of its slot for two-phase transactions if enabled by the caller, but the code forgot to acquire a spinlock when updating these fields like any other code paths. This could lead to the read of inconsistent data. Oversight in a8fd13c. Author: Sawada Masahiko Discussion: https://postgr.es/m/CAD21AoAD8_fp47191LKuecjDd3DYhoQ4TaucFco1_TEr_jQ-Zw@mail.gmail.com Backpatch-through: 15
-rw-r--r--src/backend/replication/logical/logical.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 52d1fe6269..1a58dd7649 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -555,8 +555,10 @@ CreateDecodingContext(XLogRecPtr start_lsn,
/* Mark slot to allow two_phase decoding if not already marked */
if (ctx->twophase && !slot->data.two_phase)
{
+ SpinLockAcquire(&slot->mutex);
slot->data.two_phase = true;
slot->data.two_phase_at = start_lsn;
+ SpinLockRelease(&slot->mutex);
ReplicationSlotMarkDirty();
ReplicationSlotSave();
SnapBuildSetTwoPhaseAt(ctx->snapshot_builder, start_lsn);