postgres.git / summary / log / commit / refs

commit    b9bdbf8c1a7f8df069fab276d844edcb35ebae70
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Thu Nov 29 00:12:57 2018 +0000
First released in: 12.0, 9.4.21, 9.5.16, 9.6.12, 10.7, 11.2

    Fix handling of synchronous replication for stopping WAL senders
    
    This fixes an oversight from c6c3334 which forgot that if a subset of
    WAL senders are stopping and in a sync state, other WAL senders could
    still be waiting for a WAL position to be synced while committing a
    transaction.  However the subset of stopping senders would not release
    waiters, potentially breaking synchronous replication guarantees.  This
    commit makes sure that even WAL senders stopping are able to release
    waiters and are tracked properly.
    
    On 9.4, this can also trigger an assertion failure when setting for
    example max_wal_senders to 1 where a WAL sender is not able to find
    itself as in synchronous state when the instance stops.
    
    Reported-by: Paul Guo
    Author: Paul Guo, Michael Paquier
    Discussion: https://postgr.es/m/CAEET0ZEv8VFqT3C-cQm6byOB4r4VYWcef1J21dOX-gcVhCSpmA@mail.gmail.com
    Backpatch-through: 9.4


src/backend/replication/syncrep.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c index ea6ffc0f315..08588bfcb04 100644 --- a/src/backend/replication/syncrep.c +++ b/src/backend/replication/syncrep.c @@ -366,8 +366,9 @@ SyncRepGetSynchronousStandby(void) if (walsnd->pid == 0) continue; - /* Must be streaming */ - if (walsnd->state != WALSNDSTATE_STREAMING) + /* Must be streaming or stopping */ + if (walsnd->state != WALSNDSTATE_STREAMING && + walsnd->state != WALSNDSTATE_STOPPING) continue; /* Must be synchronous */ @@ -416,10 +417,12 @@ SyncRepReleaseWaiters(void) * If this WALSender is serving a standby that is not on the list of * potential sync standbys then we have nothing to do. If we are still * starting up, still running base backup or the current flush position - * is still invalid, then leave quickly also. + * is still invalid, then leave quickly also. Streaming or stopping WAL + * senders are allowed to release waiters. */ if (MyWalSnd->sync_standby_priority == 0 || - MyWalSnd->state < WALSNDSTATE_STREAMING || + (MyWalSnd->state != WALSNDSTATE_STREAMING && + MyWalSnd->state != WALSNDSTATE_STOPPING) || XLogRecPtrIsInvalid(MyWalSnd->flush)) return; [parent: 77d2815e4579]