Commit 33c50995 authored by Alvaro Herrera's avatar Alvaro Herrera

Fix logic bug in 1632ea43

I overlooked that one condition was logically inverted.  The fix is a
little bit more involved than simply negating the condition, to make
the code easier to read.

Fix some outdated comments left by the same commit, while at it.

Author: Masahiko Sawada <sawada.mshk@gmail.com>
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: default avatarAmit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/YMRlmB3/lZw8YBH+@paquier.xyz
parent 86b222b0
...@@ -410,9 +410,9 @@ retry: ...@@ -410,9 +410,9 @@ retry:
if (IsUnderPostmaster) if (IsUnderPostmaster)
{ {
/* /*
* Get ready to sleep on the slot in case it is active if SAB_Block. * Get ready to sleep on the slot in case it is active. (We may end
* (We may end up not sleeping, but we don't want to do this while * up not sleeping, but we don't want to do this while holding the
* holding the spinlock.) * spinlock.)
*/ */
if (!nowait) if (!nowait)
ConditionVariablePrepareToSleep(&s->active_cv); ConditionVariablePrepareToSleep(&s->active_cv);
...@@ -429,22 +429,24 @@ retry: ...@@ -429,22 +429,24 @@ retry:
/* /*
* If we found the slot but it's already active in another process, we * If we found the slot but it's already active in another process, we
* either error out, return the PID of the owning process, or retry after * wait until the owning process signals us that it's been released, or
* a short wait, as caller specified. * error out.
*/ */
if (active_pid != MyProcPid) if (active_pid != MyProcPid)
{ {
if (!nowait) if (!nowait)
ereport(ERROR, {
(errcode(ERRCODE_OBJECT_IN_USE), /* Wait here until we get signaled, and then restart */
errmsg("replication slot \"%s\" is active for PID %d", ConditionVariableSleep(&s->active_cv,
NameStr(s->data.name), active_pid))); WAIT_EVENT_REPLICATION_SLOT_DROP);
ConditionVariableCancelSleep();
goto retry;
}
/* Wait here until we get signaled, and then restart */ ereport(ERROR,
ConditionVariableSleep(&s->active_cv, (errcode(ERRCODE_OBJECT_IN_USE),
WAIT_EVENT_REPLICATION_SLOT_DROP); errmsg("replication slot \"%s\" is active for PID %d",
ConditionVariableCancelSleep(); NameStr(s->data.name), active_pid)));
goto retry;
} }
else if (!nowait) else if (!nowait)
ConditionVariableCancelSleep(); /* no sleep needed after all */ ConditionVariableCancelSleep(); /* no sleep needed after all */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment