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

Commit 4c70336

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 1a990b2 commit 4c70336

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/backend/replication/syncrep.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,12 @@ SyncRepReleaseWaiters(void)
425425
* If this WALSender is serving a standby that is not on the list of
426426
* potential sync standbys then we have nothing to do. If we are still
427427
* starting up, still running base backup or the current flush position is
428-
* still invalid, then leave quickly also.
428+
* still invalid, then leave quickly also. Streaming or stopping WAL
429+
* senders are allowed to release waiters.
429430
*/
430431
if (MyWalSnd->sync_standby_priority == 0 ||
431-
MyWalSnd->state < WALSNDSTATE_STREAMING ||
432+
(MyWalSnd->state != WALSNDSTATE_STREAMING &&
433+
MyWalSnd->state != WALSNDSTATE_STOPPING) ||
432434
XLogRecPtrIsInvalid(MyWalSnd->flush))
433435
{
434436
announce_next_takeover = true;
@@ -730,8 +732,9 @@ SyncRepGetSyncStandbysQuorum(bool *am_sync)
730732
if (pid == 0)
731733
continue;
732734

733-
/* Must be streaming */
734-
if (state != WALSNDSTATE_STREAMING)
735+
/* Must be streaming or stopping */
736+
if (state != WALSNDSTATE_STREAMING &&
737+
state != WALSNDSTATE_STOPPING)
735738
continue;
736739

737740
/* Must be synchronous */
@@ -809,8 +812,9 @@ SyncRepGetSyncStandbysPriority(bool *am_sync)
809812
if (pid == 0)
810813
continue;
811814

812-
/* Must be streaming */
813-
if (state != WALSNDSTATE_STREAMING)
815+
/* Must be streaming or stopping */
816+
if (state != WALSNDSTATE_STREAMING &&
817+
state != WALSNDSTATE_STOPPING)
814818
continue;
815819

816820
/* Must be synchronous */

0 commit comments

Comments
 (0)