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

Commit bad4176

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 95c4571 commit bad4176

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/replication/syncrep.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,12 @@ SyncRepReleaseWaiters(void)
423423
* If this WALSender is serving a standby that is not on the list of
424424
* potential sync standbys then we have nothing to do. If we are still
425425
* starting up, still running base backup or the current flush position is
426-
* still invalid, then leave quickly also.
426+
* still invalid, then leave quickly also. Streaming or stopping WAL
427+
* senders are allowed to release waiters.
427428
*/
428429
if (MyWalSnd->sync_standby_priority == 0 ||
429-
MyWalSnd->state < WALSNDSTATE_STREAMING ||
430+
(MyWalSnd->state != WALSNDSTATE_STREAMING &&
431+
MyWalSnd->state != WALSNDSTATE_STOPPING) ||
430432
XLogRecPtrIsInvalid(MyWalSnd->flush))
431433
{
432434
announce_next_takeover = true;
@@ -728,8 +730,9 @@ SyncRepGetSyncStandbysQuorum(bool *am_sync)
728730
if (pid == 0)
729731
continue;
730732

731-
/* Must be streaming */
732-
if (state != WALSNDSTATE_STREAMING)
733+
/* Must be streaming or stopping */
734+
if (state != WALSNDSTATE_STREAMING &&
735+
state != WALSNDSTATE_STOPPING)
733736
continue;
734737

735738
/* Must be synchronous */
@@ -807,8 +810,9 @@ SyncRepGetSyncStandbysPriority(bool *am_sync)
807810
if (pid == 0)
808811
continue;
809812

810-
/* Must be streaming */
811-
if (state != WALSNDSTATE_STREAMING)
813+
/* Must be streaming or stopping */
814+
if (state != WALSNDSTATE_STREAMING &&
815+
state != WALSNDSTATE_STOPPING)
812816
continue;
813817

814818
/* Must be synchronous */

0 commit comments

Comments
 (0)