]> granicus.if.org Git - postgresql/commit
Fix handling of synchronous replication for stopping WAL senders
authorMichael Paquier <michael@paquier.xyz>
Thu, 29 Nov 2018 00:13:04 +0000 (09:13 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 29 Nov 2018 00:13:04 +0000 (09:13 +0900)
commitb81d08d6001068040a5c0da9bc03473feaae11c1
treef5a793f511757f8b05059bf5681c59cc261d40e8
parentc1a5caea82694006047b6193e924ffbbabc87193
Fix handling of synchronous replication for stopping WAL senders

This fixes an oversight from c6c3334 which has introduced a more strict
ordering in the way WAL senders are stopped to prevent current WAL
activity when a shutdown checkpoint is created.  After all backends are
stopped, all WAL senders are requested to stop which makes them stop any
activity, and switching their state as stopping.  Once the checkpointer
knows that all WAL senders are in a stopping state, the shutdown
checkpoint can begin, with all WAL senders activated, waiting for their
clients to flush the shutdown checkpoint record.

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 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
src/backend/replication/walsender.c