Move InRecovery and standbyState global vars to xlogutils.c.
authorHeikki Linnakangas
Sat, 31 Jul 2021 06:50:26 +0000 (09:50 +0300)
committerHeikki Linnakangas
Sat, 31 Jul 2021 06:50:26 +0000 (09:50 +0300)
They are used in code that runs both during normal operation and during
WAL replay, and needs to behave differently during replay. Move them to
xlogutils.c, because that's where we have other helper functions used by
redo routines.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/b3b71061-4919-e882-4857-27e370ab134a%40iki.fi

17 files changed:
src/backend/access/heap/visibilitymap.c
src/backend/access/transam/commit_ts.c
src/backend/access/transam/multixact.c
src/backend/access/transam/slru.c
src/backend/access/transam/varsup.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xlogutils.c
src/backend/commands/tablespace.c
src/backend/postmaster/startup.c
src/backend/storage/buffer/bufmgr.c
src/backend/storage/ipc/procarray.c
src/backend/storage/ipc/standby.c
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/proc.c
src/backend/storage/smgr/smgr.c
src/include/access/xlog.h
src/include/access/xlogutils.h

index 4720b35ee5cdc50845adbcc3560c41cae0bb413f..114fbbdd307a65495e2166036bb3f89079f90011 100644 (file)
@@ -88,7 +88,7 @@
 
 #include "access/heapam_xlog.h"
 #include "access/visibilitymap.h"
-#include "access/xlog.h"
+#include "access/xlogutils.h"
 #include "miscadmin.h"
 #include "port/pg_bitutils.h"
 #include "storage/bufmgr.h"
index 0985fa155caea741e9d23be6773834e2af6a72d5..42ea8e53f2c3f81a3cd93aad061856fd63dfb341 100644 (file)
@@ -28,6 +28,7 @@
 #include "access/htup_details.h"
 #include "access/slru.h"
 #include "access/transam.h"
+#include "access/xlogutils.h"
 #include "catalog/pg_type.h"
 #include "funcapi.h"
 #include "miscadmin.h"
index b643564f16a4ef220004e9855f27c06531456c57..e6c70ed0bc28d9c4c106a85d7a150286ffa4bc43 100644 (file)
@@ -74,8 +74,8 @@
 #include "access/twophase.h"
 #include "access/twophase_rmgr.h"
 #include "access/xact.h"
-#include "access/xlog.h"
 #include "access/xloginsert.h"
+#include "access/xlogutils.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
 #include "funcapi.h"
index 82149ad7821cd1817f64894944a4d4cbb418b1dd..7585ae24ce97615e66ee36d5717111e8853b0f54 100644 (file)
@@ -54,6 +54,7 @@
 #include "access/slru.h"
 #include "access/transam.h"
 #include "access/xlog.h"
+#include "access/xlogutils.h"
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "storage/fd.h"
index 5b4898bb7862b8c665a9e1d09ca220e7e82cc609..a6e98e71bd1d71019b52cd9401ff4fdf1e16efc5 100644 (file)
@@ -18,7 +18,7 @@
 #include "access/subtrans.h"
 #include "access/transam.h"
 #include "access/xact.h"
-#include "access/xlog.h"
+#include "access/xlogutils.h"
 #include "commands/dbcommands.h"
 #include "miscadmin.h"
 #include "postmaster/autovacuum.h"
index 1e601d6282fcf0562be56dbf528ad87085f88801..efb3ca273ed9549adb72466920103b7d94353352 100644 (file)
@@ -193,22 +193,6 @@ CheckpointStatsData CheckpointStats;
  */
 TimeLineID ThisTimeLineID = 0;
 
-/*
- * Are we doing recovery from XLOG?
- *
- * This is only ever true in the startup process; it should be read as meaning
- * "this process is replaying WAL records", rather than "the system is in
- * recovery mode".  It should be examined primarily by functions that need
- * to act differently when called from a WAL redo function (e.g., to skip WAL
- * logging).  To check whether the system is in recovery regardless of which
- * process you're running in, use RecoveryInProgress() but only after shared
- * memory startup and lock initialization.
- */
-bool       InRecovery = false;
-
-/* Are we in Hot Standby mode? Only valid in startup process, see xlog.h */
-HotStandbyState standbyState = STANDBY_DISABLED;
-
 static XLogRecPtr LastRec;
 
 /* Local copy of WalRcv->flushedUpto */
index d17d660f46053e466b843499f54d6576c3d45855..b1702bc6bef41f8244792a72b11e8e0562273afd 100644 (file)
@@ -25,6 +25,7 @@
 #include "access/xlogutils.h"
 #include "miscadmin.h"
 #include "pgstat.h"
+#include "storage/fd.h"
 #include "storage/smgr.h"
 #include "utils/guc.h"
 #include "utils/hsearch.h"
 /* GUC variable */
 bool       ignore_invalid_pages = false;
 
+/*
+ * Are we doing recovery from XLOG?
+ *
+ * This is only ever true in the startup process; it should be read as meaning
+ * "this process is replaying WAL records", rather than "the system is in
+ * recovery mode".  It should be examined primarily by functions that need
+ * to act differently when called from a WAL redo function (e.g., to skip WAL
+ * logging).  To check whether the system is in recovery regardless of which
+ * process you're running in, use RecoveryInProgress() but only after shared
+ * memory startup and lock initialization.
+ *
+ * This is updated from xlog.c, but lives here because it's mostly read by
+ * WAL redo functions.
+ */
+bool       InRecovery = false;
+
+/* Are we in Hot Standby mode? Only valid in startup process, see xlogutils.h */
+HotStandbyState standbyState = STANDBY_DISABLED;
+
 /*
  * During XLOG replay, we may see XLOG records for incremental updates of
  * pages that no longer exist, because their relation was later dropped or
index 0385fd61214d4b0a55d07e4983cec04d24b8dbd2..a54239a8b3555784f878b89d28afb172119d050a 100644 (file)
@@ -56,8 +56,8 @@
 #include "access/sysattr.h"
 #include "access/tableam.h"
 #include "access/xact.h"
-#include "access/xlog.h"
 #include "access/xloginsert.h"
+#include "access/xlogutils.h"
 #include "catalog/catalog.h"
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
index 69077bd207516ea08d69cf2f2dec52eb6ff26425..0f4f00d6895194cf2d6e4aa9daeaf0439ddb0473 100644 (file)
@@ -20,6 +20,7 @@
 #include "postgres.h"
 
 #include "access/xlog.h"
+#include "access/xlogutils.h"
 #include "libpq/pqsignal.h"
 #include "miscadmin.h"
 #include "pgstat.h"
index 86ef607ff3811b73880e4461ad71149bebc5cf32..33d99f604ade1d3cbef59da60818442320c6800f 100644 (file)
@@ -34,7 +34,7 @@
 #include 
 
 #include "access/tableam.h"
-#include "access/xlog.h"
+#include "access/xlogutils.h"
 #include "catalog/catalog.h"
 #include "catalog/storage.h"
 #include "executor/instrument.h"
index 09c97c58b875996629d16ea1ac0739f0c81c9109..c7816fcfb30502453f9e3fac94e58aed09ffe668 100644 (file)
@@ -52,7 +52,7 @@
 #include "access/transam.h"
 #include "access/twophase.h"
 #include "access/xact.h"
-#include "access/xlog.h"
+#include "access/xlogutils.h"
 #include "catalog/catalog.h"
 #include "catalog/pg_authid.h"
 #include "commands/dbcommands.h"
index aeecaf6cabf5b84e5e191ef0231b71aef57c6964..077251c1a651120769281b3ea75cded2bdb96e43 100644 (file)
@@ -19,8 +19,8 @@
 #include "access/transam.h"
 #include "access/twophase.h"
 #include "access/xact.h"
-#include "access/xlog.h"
 #include "access/xloginsert.h"
+#include "access/xlogutils.h"
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "storage/bufmgr.h"
index 8c2138f1071dc53c5f8002d382359f1133a4472c..364654e10603598ee96feb756477f4c9b7adfa7c 100644 (file)
@@ -37,6 +37,7 @@
 #include "access/twophase_rmgr.h"
 #include "access/xact.h"
 #include "access/xlog.h"
+#include "access/xlogutils.h"
 #include "miscadmin.h"
 #include "pg_trace.h"
 #include "pgstat.h"
index 2575ea1ca0d9ac14f8955121720a3789e909319c..b7d9da0aa9f7f51b4d17e95893cc5380fa6dee3e 100644 (file)
@@ -37,7 +37,7 @@
 
 #include "access/transam.h"
 #include "access/twophase.h"
-#include "access/xact.h"
+#include "access/xlogutils.h"
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "postmaster/autovacuum.h"
index 4dc24649df982dbc187665b3d0d4d0fca74bd75a..0fcef4994be1f619c965884cbb00d99c03ad4b32 100644 (file)
@@ -17,7 +17,7 @@
  */
 #include "postgres.h"
 
-#include "access/xlog.h"
+#include "access/xlogutils.h"
 #include "lib/ilist.h"
 #include "storage/bufmgr.h"
 #include "storage/ipc.h"
index ccfcf43d62a72b50675ae3cc89d8065a306f6cec..0a8ede700defc658925d3d60383ac94fd4e25988 100644 (file)
@@ -31,48 +31,6 @@ extern int   sync_method;
 
 extern PGDLLIMPORT TimeLineID ThisTimeLineID;  /* current TLI */
 
-/*
- * Prior to 8.4, all activity during recovery was carried out by the startup
- * process. This local variable continues to be used in many parts of the
- * code to indicate actions taken by RecoveryManagers. Other processes that
- * potentially perform work during recovery should check RecoveryInProgress().
- * See XLogCtl notes in xlog.c.
- */
-extern bool InRecovery;
-
-/*
- * Like InRecovery, standbyState is only valid in the startup process.
- * In all other processes it will have the value STANDBY_DISABLED (so
- * InHotStandby will read as false).
- *
- * In DISABLED state, we're performing crash recovery or hot standby was
- * disabled in postgresql.conf.
- *
- * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but
- * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record
- * to initialize our primary-transaction tracking system.
- *
- * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING
- * state. The tracked information might still be incomplete, so we can't allow
- * connections yet, but redo functions must update the in-memory state when
- * appropriate.
- *
- * In SNAPSHOT_READY mode, we have full knowledge of transactions that are
- * (or were) running on the primary at the current WAL location. Snapshots
- * can be taken, and read-only queries can be run.
- */
-typedef enum
-{
-   STANDBY_DISABLED,
-   STANDBY_INITIALIZED,
-   STANDBY_SNAPSHOT_PENDING,
-   STANDBY_SNAPSHOT_READY
-} HotStandbyState;
-
-extern HotStandbyState standbyState;
-
-#define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
-
 /*
  * Recovery target type.
  * Only set during a Point in Time recovery, not when in standby mode.
index 9ac602b674d1a819719cb5b7e2336991c32c8f4a..a5cb3d322c52f9c6827a7a98c670e01dbdc48d09 100644 (file)
 #include "access/xlogreader.h"
 #include "storage/bufmgr.h"
 
+/*
+ * Prior to 8.4, all activity during recovery was carried out by the startup
+ * process. This local variable continues to be used in many parts of the
+ * code to indicate actions taken by RecoveryManagers. Other processes that
+ * potentially perform work during recovery should check RecoveryInProgress().
+ * See XLogCtl notes in xlog.c.
+ */
+extern bool InRecovery;
+
+/*
+ * Like InRecovery, standbyState is only valid in the startup process.
+ * In all other processes it will have the value STANDBY_DISABLED (so
+ * InHotStandby will read as false).
+ *
+ * In DISABLED state, we're performing crash recovery or hot standby was
+ * disabled in postgresql.conf.
+ *
+ * In INITIALIZED state, we've run InitRecoveryTransactionEnvironment, but
+ * we haven't yet processed a RUNNING_XACTS or shutdown-checkpoint WAL record
+ * to initialize our primary-transaction tracking system.
+ *
+ * When the transaction tracking is initialized, we enter the SNAPSHOT_PENDING
+ * state. The tracked information might still be incomplete, so we can't allow
+ * connections yet, but redo functions must update the in-memory state when
+ * appropriate.
+ *
+ * In SNAPSHOT_READY mode, we have full knowledge of transactions that are
+ * (or were) running on the primary at the current WAL location. Snapshots
+ * can be taken, and read-only queries can be run.
+ */
+typedef enum
+{
+   STANDBY_DISABLED,
+   STANDBY_INITIALIZED,
+   STANDBY_SNAPSHOT_PENDING,
+   STANDBY_SNAPSHOT_READY
+} HotStandbyState;
+
+extern HotStandbyState standbyState;
+
+#define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
+
 
 extern bool XLogHaveInvalidPages(void);
 extern void XLogCheckInvalidPages(void);