Commit 72758999 authored by Robert Haas's avatar Robert Haas

Move synchronous_standbys_defined updates from WAL writer to BG writer.

This is advantageous because the BG writer is alive until much later in
the shutdown sequence than WAL writer; we want to make sure that it's
possible to shut off synchronous replication during a smart shutdown,
else it might not be possible to complete the shutdown at all.

Per very reasonable gripes from Fujii Masao and Simon Riggs.
parent f78ba0a7
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "miscadmin.h" #include "miscadmin.h"
#include "pgstat.h" #include "pgstat.h"
#include "postmaster/bgwriter.h" #include "postmaster/bgwriter.h"
#include "replication/syncrep.h"
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
#include "storage/fd.h" #include "storage/fd.h"
#include "storage/ipc.h" #include "storage/ipc.h"
...@@ -363,6 +364,9 @@ BackgroundWriterMain(void) ...@@ -363,6 +364,9 @@ BackgroundWriterMain(void)
if (RecoveryInProgress()) if (RecoveryInProgress())
ThisTimeLineID = GetRecoveryTargetTLI(); ThisTimeLineID = GetRecoveryTargetTLI();
/* Do this once before starting the loop, then just at SIGHUP time. */
SyncRepUpdateSyncStandbysDefined();
/* /*
* Loop forever * Loop forever
*/ */
...@@ -389,6 +393,8 @@ BackgroundWriterMain(void) ...@@ -389,6 +393,8 @@ BackgroundWriterMain(void)
{ {
got_SIGHUP = false; got_SIGHUP = false;
ProcessConfigFile(PGC_SIGHUP); ProcessConfigFile(PGC_SIGHUP);
/* update global shmem state for sync rep */
SyncRepUpdateSyncStandbysDefined();
} }
if (checkpoint_requested) if (checkpoint_requested)
{ {
...@@ -704,6 +710,8 @@ CheckpointWriteDelay(int flags, double progress) ...@@ -704,6 +710,8 @@ CheckpointWriteDelay(int flags, double progress)
{ {
got_SIGHUP = false; got_SIGHUP = false;
ProcessConfigFile(PGC_SIGHUP); ProcessConfigFile(PGC_SIGHUP);
/* update global shmem state for sync rep */
SyncRepUpdateSyncStandbysDefined();
} }
AbsorbFsyncRequests(); AbsorbFsyncRequests();
......
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
#include "libpq/pqsignal.h" #include "libpq/pqsignal.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "postmaster/walwriter.h" #include "postmaster/walwriter.h"
#include "replication/syncrep.h"
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
#include "storage/fd.h" #include "storage/fd.h"
#include "storage/ipc.h" #include "storage/ipc.h"
...@@ -217,9 +216,6 @@ WalWriterMain(void) ...@@ -217,9 +216,6 @@ WalWriterMain(void)
*/ */
PG_SETMASK(&UnBlockSig); PG_SETMASK(&UnBlockSig);
/* Do this once before starting the loop, then just at SIGHUP time. */
SyncRepUpdateSyncStandbysDefined();
/* /*
* Loop forever * Loop forever
*/ */
...@@ -241,8 +237,6 @@ WalWriterMain(void) ...@@ -241,8 +237,6 @@ WalWriterMain(void)
{ {
got_SIGHUP = false; got_SIGHUP = false;
ProcessConfigFile(PGC_SIGHUP); ProcessConfigFile(PGC_SIGHUP);
/* update global shmem state for sync rep */
SyncRepUpdateSyncStandbysDefined();
} }
if (shutdown_requested) if (shutdown_requested)
{ {
......
...@@ -557,9 +557,9 @@ SyncRepWakeQueue(bool all) ...@@ -557,9 +557,9 @@ SyncRepWakeQueue(bool all)
} }
/* /*
* WAL writer calls this as needed to update the shared sync_standbys_defined * The background writer calls this as needed to update the shared
* flag, so that backends don't remain permanently wedged if * sync_standbys_defined flag, so that backends don't remain permanently wedged
* synchronous_standby_names is unset. It's safe to check the current value * if synchronous_standby_names is unset. It's safe to check the current value
* without the lock, because it's only ever updated by one process. But we * without the lock, because it's only ever updated by one process. But we
* must take the lock to change it. * must take the lock to change it.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment