Skip to content

Commit b41a85f

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 7a8cb4a commit b41a85f

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
@@ -962,25 +962,33 @@ LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, XLogRecPtr restart
962962
{
963963
slot->candidate_restart_valid = current_lsn;
964964
slot->candidate_restart_lsn = restart_lsn;
965+
SpinLockRelease(&slot->mutex);
965966

966967
elog(DEBUG1, "got new restart lsn %X/%X at %X/%X",
967968
(uint32) (restart_lsn >> 32), (uint32) restart_lsn,
968969
(uint32) (current_lsn >> 32), (uint32) current_lsn);
969970
}
970971
else
971972
{
973+
XLogRecPtr candidate_restart_lsn;
974+
XLogRecPtr candidate_restart_valid;
975+
XLogRecPtr confirmed_flush;
976+
977+
candidate_restart_lsn = slot->candidate_restart_lsn;
978+
candidate_restart_valid = slot->candidate_restart_valid;
979+
confirmed_flush = slot->data.confirmed_flush;
980+
SpinLockRelease(&slot->mutex);
981+
972982
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",
973983
(uint32) (restart_lsn >> 32), (uint32) restart_lsn,
974984
(uint32) (current_lsn >> 32), (uint32) current_lsn,
975-
(uint32) (slot->candidate_restart_lsn >> 32),
976-
(uint32) slot->candidate_restart_lsn,
977-
(uint32) (slot->candidate_restart_valid >> 32),
978-
(uint32) slot->candidate_restart_valid,
979-
(uint32) (slot->data.confirmed_flush >> 32),
980-
(uint32) slot->data.confirmed_flush
981-
);
985+
(uint32) (candidate_restart_lsn >> 32),
986+
(uint32) candidate_restart_lsn,
987+
(uint32) (candidate_restart_valid >> 32),
988+
(uint32) candidate_restart_valid,
989+
(uint32) (confirmed_flush >> 32),
990+
(uint32) confirmed_flush);
982991
}
983-
SpinLockRelease(&slot->mutex);
984992

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

0 commit comments

Comments
 (0)