Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8340eba

Browse files
committed
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
1 parent 63d8350 commit 8340eba

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/backend/replication/syncrep.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,12 @@ SyncRepReleaseWaiters(void)
397397
* If this WALSender is serving a standby that is not on the list of
398398
* potential sync standbys then we have nothing to do. If we are still
399399
* starting up, still running base backup or the current flush position is
400-
* still invalid, then leave quickly also.
400+
* still invalid, then leave quickly also. Streaming or stopping WAL
401+
* senders are allowed to release waiters.
401402
*/
402403
if (MyWalSnd->sync_standby_priority == 0 ||
403-
MyWalSnd->state < WALSNDSTATE_STREAMING ||
404+
(MyWalSnd->state != WALSNDSTATE_STREAMING &&
405+
MyWalSnd->state != WALSNDSTATE_STOPPING) ||
404406
XLogRecPtrIsInvalid(MyWalSnd->flush))
405407
{
406408
announce_next_takeover = true;
@@ -585,8 +587,9 @@ SyncRepGetSyncStandbys(bool *am_sync)
585587
if (walsnd->pid == 0)
586588
continue;
587589

588-
/* Must be streaming */
589-
if (walsnd->state != WALSNDSTATE_STREAMING)
590+
/* Must be streaming or stopping */
591+
if (walsnd->state != WALSNDSTATE_STREAMING &&
592+
walsnd->state != WALSNDSTATE_STOPPING)
590593
continue;
591594

592595
/* Must be synchronous */

0 commit comments

Comments
 (0)