diff options
author | Tom Lane | 2012-07-18 19:28:10 +0000 |
---|---|---|
committer | Tom Lane | 2012-07-18 19:28:10 +0000 |
commit | 4a9c30a8a1d3a786abc4b8d95f0182463f66f919 (patch) | |
tree | 1694f9ac5f465b8b1c364010ed3fc1a731e36177 /src/include/miscadmin.h | |
parent | 3855968f328918b6cd1401dd11d109d471a54d40 (diff) |
Fix management of pendingOpsTable in auxiliary processes.
mdinit() was misusing IsBootstrapProcessingMode() to decide whether to
create an fsync pending-operations table in the current process. This led
to creating a table not only in the startup and checkpointer processes as
intended, but also in the bgwriter process, not to mention other auxiliary
processes such as walwriter and walreceiver. Creation of the table in the
bgwriter is fatal, because it absorbs fsync requests that should have gone
to the checkpointer; instead they just sit in bgwriter local memory and are
never acted on. So writes performed by the bgwriter were not being fsync'd
which could result in data loss after an OS crash. I think there is no
live bug with respect to walwriter and walreceiver because those never
perform any writes of shared buffers; but the potential is there for
future breakage in those processes too.
To fix, make AuxiliaryProcessMain() export the current process's
AuxProcType as a global variable, and then make mdinit() test directly for
the types of aux process that should have a pendingOpsTable. Having done
that, we might as well also get rid of the random bool flags such as
am_walreceiver that some of the aux processes had grown. (Note that we
could not have fixed the bug by examining those variables in mdinit(),
because it's called from BaseInit() which is run by AuxiliaryProcessMain()
before entering any of the process-type-specific code.)
Back-patch to 9.2, where the problem was introduced by the split-up of
bgwriter and checkpointer processes. The bogus pendingOpsTable exists
in walwriter and walreceiver processes in earlier branches, but absent
any evidence that it causes actual problems there, I'll leave the older
branches alone.
Diffstat (limited to 'src/include/miscadmin.h')
-rw-r--r-- | src/include/miscadmin.h | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index b186eed8f47..8df2a28126a 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -328,8 +328,8 @@ extern bool superuser_arg(Oid roleid); /* given user is superuser */ * initialization is complete. Some code behaves differently when executed * in this mode to enable system bootstrapping. * - * If a POSTGRES binary is in normal mode, then all code may be executed - * normally. + * If a POSTGRES backend process is in normal mode, then all code may be + * executed normally. */ typedef enum ProcessingMode @@ -341,9 +341,11 @@ typedef enum ProcessingMode extern ProcessingMode Mode; -#define IsBootstrapProcessingMode() ((bool)(Mode == BootstrapProcessing)) -#define IsInitProcessingMode() ((bool)(Mode == InitProcessing)) -#define IsNormalProcessingMode() ((bool)(Mode == NormalProcessing)) +#define IsBootstrapProcessingMode() (Mode == BootstrapProcessing) +#define IsInitProcessingMode() (Mode == InitProcessing) +#define IsNormalProcessingMode() (Mode == NormalProcessing) + +#define GetProcessingMode() Mode #define SetProcessingMode(mode) \ do { \ @@ -353,7 +355,35 @@ extern ProcessingMode Mode; Mode = (mode); \ } while(0) -#define GetProcessingMode() Mode + +/* + * Auxiliary-process type identifiers. These used to be in bootstrap.h + * but it seems saner to have them here, with the ProcessingMode stuff. + * The MyAuxProcType global is defined and set in bootstrap.c. + */ + +typedef enum +{ + NotAnAuxProcess = -1, + CheckerProcess = 0, + BootstrapProcess, + StartupProcess, + BgWriterProcess, + CheckpointerProcess, + WalWriterProcess, + WalReceiverProcess, + + NUM_AUXPROCTYPES /* Must be last! */ +} AuxProcType; + +extern AuxProcType MyAuxProcType; + +#define AmBootstrapProcess() (MyAuxProcType == BootstrapProcess) +#define AmStartupProcess() (MyAuxProcType == StartupProcess) +#define AmBackgroundWriterProcess() (MyAuxProcType == BgWriterProcess) +#define AmCheckpointerProcess() (MyAuxProcType == CheckpointerProcess) +#define AmWalWriterProcess() (MyAuxProcType == WalWriterProcess) +#define AmWalReceiverProcess() (MyAuxProcType == WalReceiverProcess) /***************************************************************************** |