Skip to content

Commit 03aa25b

Browse files
committed
Fix instance of elog() called while holding a spinlock
This broke the project rule to not call any complex code while a spinlock is held. Issue introduced by b89e151. Discussion: https://postgr.es/m/20200602.161518.1399689010416646074.horikyota.ntt@gmail.com Backpatch-through: 9.5
1 parent 3d474a0 commit 03aa25b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/backend/replication/logical/logical.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -974,25 +974,33 @@ LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart
974974
{
975975
slot->candidate_restart_valid = current_lsn;
976976
slot->candidate_restart_lsn = restart_lsn;
977+
SpinLockRelease(&slot->mutex);
977978

978979
elog(DEBUG1, "got new restart lsn %X/%X at %X/%X",
979980
(uint32) (restart_lsn >> 32), (uint32) restart_lsn,
980981
(uint32) (current_lsn >> 32), (uint32) current_lsn);
981982
}
982983
else
983984
{
985+
XLogRecPtr candidate_restart_lsn;
986+
XLogRecPtr candidate_restart_valid;
987+
XLogRecPtr confirmed_flush;
988+
989+
candidate_restart_lsn = slot->candidate_restart_lsn;
990+
candidate_restart_valid = slot->candidate_restart_valid;
991+
confirmed_flush = slot->data.confirmed_flush;
992+
SpinLockRelease(&slot->mutex);
993+
984994
elog(DEBUG1, "failed to increase restart lsn: proposed %X/%X, after %X/%X, current candidate %X/%X, current after %X/%X, flushed up to %X/%X",
985995
(uint32) (restart_lsn >> 32), (uint32) restart_lsn,
986996
(uint32) (current_lsn >> 32), (uint32) current_lsn,
987-
(uint32) (slot->candidate_restart_lsn >> 32),
988-
(uint32) slot->candidate_restart_lsn,
989-
(uint32) (slot->candidate_restart_valid >> 32),
990-
(uint32) slot->candidate_restart_valid,
991-
(uint32) (slot->data.confirmed_flush >> 32),
992-
(uint32) slot->data.confirmed_flush
993-
);
997+
(uint32) (candidate_restart_lsn >> 32),
998+
(uint32) candidate_restart_lsn,
999+
(uint32) (candidate_restart_valid >> 32),
1000+
(uint32) candidate_restart_valid,
1001+
(uint32) (confirmed_flush >> 32),
1002+
(uint32) confirmed_flush);
9941003
}
995-
SpinLockRelease(&slot->mutex);
9961004

9971005
/* candidates are already valid with the current flush position, apply */
9981006
if (updated_lsn)

0 commit comments

Comments
 (0)