mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-07 03:26:58 +02:00
Make pg_promote() detect postmaster death while waiting for promotion to end.
Previously even if postmaster died and WaitLatch() woke up with that event while pg_promote() was waiting for the standby promotion to finish, pg_promote() did nothing special and kept waiting until timeout occurred. This could cause a busy loop. This patch make pg_promote() return false immediately when postmaster dies, to avoid such a busy loop. Back-patch to v12 where pg_promote() was added. Author: Fujii Masao Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/CAHGQGwEs9ROgSp+QF+YdDU+xP8W=CY1k-_Ov-d_Z3JY+to3eXA@mail.gmail.com
This commit is contained in:
parent
4c3e750ab4
commit
7aa815a7aa
@ -759,6 +759,8 @@ pg_promote(PG_FUNCTION_ARGS)
|
|||||||
#define WAITS_PER_SECOND 10
|
#define WAITS_PER_SECOND 10
|
||||||
for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++)
|
for (i = 0; i < WAITS_PER_SECOND * wait_seconds; i++)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
ResetLatch(MyLatch);
|
ResetLatch(MyLatch);
|
||||||
|
|
||||||
if (!RecoveryInProgress())
|
if (!RecoveryInProgress())
|
||||||
@ -766,10 +768,17 @@ pg_promote(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
CHECK_FOR_INTERRUPTS();
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
(void) WaitLatch(MyLatch,
|
rc = WaitLatch(MyLatch,
|
||||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||||
1000L / WAITS_PER_SECOND,
|
1000L / WAITS_PER_SECOND,
|
||||||
WAIT_EVENT_PROMOTE);
|
WAIT_EVENT_PROMOTE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Emergency bailout if postmaster has died. This is to avoid the
|
||||||
|
* necessity for manual cleanup of all postmaster children.
|
||||||
|
*/
|
||||||
|
if (rc & WL_POSTMASTER_DEATH)
|
||||||
|
PG_RETURN_BOOL(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
|
Loading…
Reference in New Issue
Block a user