8000 Always treat a standby returning an an invalid flush location as async · lhcezar/postgres@b8aca12 · GitHub
[go: up one dir, main page]

Skip to content

Commit b8aca12

Browse files
committed
Always treat a standby returning an an invalid flush location as async
This ensures that a standby such as pg_receivexlog will not be selected as sync standby - which would cause the master to block waiting for a location that could never happen. Fujii Masao
1 parent 119027e commit b8aca12

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/backend/replication/syncrep.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,12 @@ SyncRepReleaseWaiters(void)
379379
/*
380380
* If this WALSender is serving a standby that is not on the list of
381381
* potential standbys then we have nothing to do. If we are still starting
382-
* up or still running base backup, then leave quickly also.
382+
* up, still running base backup or the current flush position is still
383+
* invalid, then leave quickly also.
383384
*/
384385
if (MyWalSnd->sync_standby_priority == 0 ||
385-
MyWalSnd->state < WALSNDSTATE_STREAMING)
386+
MyWalSnd->state < WALSNDSTATE_STREAMING ||
387+
XLogRecPtrIsInvalid(MyWalSnd->flush))
386388
return;
387389

388390
/*
@@ -402,7 +404,8 @@ SyncRepReleaseWaiters(void)
402404
walsnd->state == WALSNDSTATE_STREAMING &&
403405
walsnd->sync_standby_priority > 0 &&
404406
(priority == 0 ||
405-
priority > walsnd->sync_standby_priority))
407+
priority > walsnd->sync_standby_priority) &&
408+
!XLogRecPtrIsInvalid(walsnd->flush))
406409
{
407410
priority = walsnd->sync_standby_priority;
408411
syncWalSnd = walsnd;

src/backend/replication/walreceiver.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ WalReceiverMain(void)
276276
walrcv_connect(conninfo, startpoint);
277277
DisableWalRcvImmediateExit();
278278

279+
/* Initialize LogstreamResult, reply_message and feedback_message */
280+
LogstreamResult.Write = LogstreamResult.Flush = GetXLogReplayRecPtr();
281+
MemSet(&reply_message, 0, sizeof(reply_message));
282+
MemSet(&feedback_message, 0, sizeof(feedback_message));
283+
279284
/* Loop until end-of-streaming or error */
280285
for (;;)
281286
{

src/backend/replication/walsender.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,12 +1443,19 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
14431443

14441444
if (walsnd->pid != 0)
14451445
{
1446-
sync_priority[i] = walsnd->sync_standby_priority;
1446+
/*
1447+
* Treat a standby such as a pg_basebackup background process
1448+
* which always returns an invalid flush location, as an
1449+
* asynchronous standby.
1450+
*/
1451+
sync_priority[i] = XLogRecPtrIsInvalid(walsnd->flush) ?
1452+
0 : walsnd->sync_standby_priority;
14471453

14481454
if (walsnd->state == WALSNDSTATE_STREAMING &&
14491455
walsnd->sync_standby_priority > 0 &&
14501456
(priority == 0 ||
1451-
priority > walsnd->sync_standby_priority))
1457+
priority > walsnd->sync_standby_priority) &&
1458+
!XLogRecPtrIsInvalid(walsnd->flush))
14521459
{
14531460
priority = walsnd->sync_standby_priority;
14541461
sync_standby = i;

0 commit comments

Comments
 (0)
0