mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-26 17:27:18 +02:00
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
This commit is contained in:
parent
95c4571812
commit
bad41764a4
@ -423,10 +423,12 @@ SyncRepReleaseWaiters(void)
|
|||||||
* If this WALSender is serving a standby that is not on the list of
|
* 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
|
* 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
|
* starting up, still running base backup or the current flush position is
|
||||||
* still invalid, then leave quickly also.
|
* still invalid, then leave quickly also. Streaming or stopping WAL
|
||||||
|
* senders are allowed to release waiters.
|
||||||
*/
|
*/
|
||||||
if (MyWalSnd->sync_standby_priority == 0 ||
|
if (MyWalSnd->sync_standby_priority == 0 ||
|
||||||
MyWalSnd->state < WALSNDSTATE_STREAMING ||
|
(MyWalSnd->state != WALSNDSTATE_STREAMING &&
|
||||||
|
MyWalSnd->state != WALSNDSTATE_STOPPING) ||
|
||||||
XLogRecPtrIsInvalid(MyWalSnd->flush))
|
XLogRecPtrIsInvalid(MyWalSnd->flush))
|
||||||
{
|
{
|
||||||
announce_next_takeover = true;
|
announce_next_takeover = true;
|
||||||
@ -728,8 +730,9 @@ SyncRepGetSyncStandbysQuorum(bool *am_sync)
|
|||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Must be streaming */
|
/* Must be streaming or stopping */
|
||||||
if (state != WALSNDSTATE_STREAMING)
|
if (state != WALSNDSTATE_STREAMING &&
|
||||||
|
state != WALSNDSTATE_STOPPING)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Must be synchronous */
|
/* Must be synchronous */
|
||||||
@ -807,8 +810,9 @@ SyncRepGetSyncStandbysPriority(bool *am_sync)
|
|||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Must be streaming */
|
/* Must be streaming or stopping */
|
||||||
if (state != WALSNDSTATE_STREAMING)
|
if (state != WALSNDSTATE_STREAMING &&
|
||||||
|
state != WALSNDSTATE_STOPPING)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Must be synchronous */
|
/* Must be synchronous */
|
||||||
|
Loading…
Reference in New Issue
Block a user