]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Move definition of XLogRecoveryCtlData to xlogrecovery.h
authorMichael Paquier <michael@paquier.xyz>
Thu, 5 Mar 2026 03:17:47 +0000 (12:17 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 5 Mar 2026 03:17:47 +0000 (12:17 +0900)
XLogRecoveryCtlData is the structure that stores the shared-memory state
of WAL recovery, including information such as promotion requests, the
timeline ID (TLI), and the LSNs of replayed records.

This refactoring is independently useful because it allows code outside
of core to access the recovery state in live.  It will be used by an
upcoming patch that introduces a SQL function for querying this
information, that can be accessed on a standby once a consistent state
has been reached.  This only moves code around, changing nothing
functionally.

Author: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/CABPTF7W+Nody-+P9y4PNk37-QWuLpfUrEonHuEhrX+Vx9Kq+Kw@mail.gmail.com

src/backend/access/transam/xlogrecovery.c
src/include/access/xlogrecovery.h

index ecd66fd86a486bd87487afe6ba95b95944190c3d..31806dcf00889a948c5a8301ad31d3178fc65521 100644 (file)
@@ -304,71 +304,7 @@ bool               reachedConsistency = false;
 static char *replay_image_masked = NULL;
 static char *primary_image_masked = NULL;
 
-
-/*
- * Shared-memory state for WAL recovery.
- */
-typedef struct XLogRecoveryCtlData
-{
-       /*
-        * SharedHotStandbyActive indicates if we allow hot standby queries to be
-        * run.  Protected by info_lck.
-        */
-       bool            SharedHotStandbyActive;
-
-       /*
-        * SharedPromoteIsTriggered indicates if a standby promotion has been
-        * triggered.  Protected by info_lck.
-        */
-       bool            SharedPromoteIsTriggered;
-
-       /*
-        * recoveryWakeupLatch is used to wake up the startup process to continue
-        * WAL replay, if it is waiting for WAL to arrive or promotion to be
-        * requested.
-        *
-        * Note that the startup process also uses another latch, its procLatch,
-        * to wait for recovery conflict. If we get rid of recoveryWakeupLatch for
-        * signaling the startup process in favor of using its procLatch, which
-        * comports better with possible generic signal handlers using that latch.
-        * But we should not do that because the startup process doesn't assume
-        * that it's waken up by walreceiver process or SIGHUP signal handler
-        * while it's waiting for recovery conflict. The separate latches,
-        * recoveryWakeupLatch and procLatch, should be used for inter-process
-        * communication for WAL replay and recovery conflict, respectively.
-        */
-       Latch           recoveryWakeupLatch;
-
-       /*
-        * Last record successfully replayed.
-        */
-       XLogRecPtr      lastReplayedReadRecPtr; /* start position */
-       XLogRecPtr      lastReplayedEndRecPtr;  /* end+1 position */
-       TimeLineID      lastReplayedTLI;        /* timeline */
-
-       /*
-        * When we're currently replaying a record, ie. in a redo function,
-        * replayEndRecPtr points to the end+1 of the record being replayed,
-        * otherwise it's equal to lastReplayedEndRecPtr.
-        */
-       XLogRecPtr      replayEndRecPtr;
-       TimeLineID      replayEndTLI;
-       /* timestamp of last COMMIT/ABORT record replayed (or being replayed) */
-       TimestampTz recoveryLastXTime;
-
-       /*
-        * timestamp of when we started replaying the current chunk of WAL data,
-        * only relevant for replication or archive recovery
-        */
-       TimestampTz currentChunkStartTime;
-       /* Recovery pause state */
-       RecoveryPauseState recoveryPauseState;
-       ConditionVariable recoveryNotPausedCV;
-
-       slock_t         info_lck;               /* locks shared variables shown above */
-} XLogRecoveryCtlData;
-
-static XLogRecoveryCtlData *XLogRecoveryCtl = NULL;
+XLogRecoveryCtlData *XLogRecoveryCtl = NULL;
 
 /*
  * abortedRecPtr is the start pointer of a broken record at end of WAL when
index f926d89cb2fb61810b682c5f64a42969d7b6e006..2842106b285804fff8860c1d64bc5612f7efadbf 100644 (file)
@@ -14,6 +14,8 @@
 #include "access/xlogreader.h"
 #include "catalog/pg_control.h"
 #include "lib/stringinfo.h"
+#include "storage/condition_variable.h"
+#include "storage/latch.h"
 #include "utils/timestamp.h"
 
 /*
@@ -58,6 +60,71 @@ typedef enum RecoveryPauseState
        RECOVERY_PAUSED,                        /* recovery is paused */
 } RecoveryPauseState;
 
+/*
+ * Shared-memory state for WAL recovery.
+ */
+typedef struct XLogRecoveryCtlData
+{
+       /*
+        * SharedHotStandbyActive indicates if we allow hot standby queries to be
+        * run.  Protected by info_lck.
+        */
+       bool            SharedHotStandbyActive;
+
+       /*
+        * SharedPromoteIsTriggered indicates if a standby promotion has been
+        * triggered.  Protected by info_lck.
+        */
+       bool            SharedPromoteIsTriggered;
+
+       /*
+        * recoveryWakeupLatch is used to wake up the startup process to continue
+        * WAL replay, if it is waiting for WAL to arrive or promotion to be
+        * requested.
+        *
+        * Note that the startup process also uses another latch, its procLatch,
+        * to wait for recovery conflict. If we get rid of recoveryWakeupLatch for
+        * signaling the startup process in favor of using its procLatch, which
+        * comports better with possible generic signal handlers using that latch.
+        * But we should not do that because the startup process doesn't assume
+        * that it's waken up by walreceiver process or SIGHUP signal handler
+        * while it's waiting for recovery conflict. The separate latches,
+        * recoveryWakeupLatch and procLatch, should be used for inter-process
+        * communication for WAL replay and recovery conflict, respectively.
+        */
+       Latch           recoveryWakeupLatch;
+
+       /*
+        * Last record successfully replayed.
+        */
+       XLogRecPtr      lastReplayedReadRecPtr; /* start position */
+       XLogRecPtr      lastReplayedEndRecPtr;  /* end+1 position */
+       TimeLineID      lastReplayedTLI;        /* timeline */
+
+       /*
+        * When we're currently replaying a record, ie. in a redo function,
+        * replayEndRecPtr points to the end+1 of the record being replayed,
+        * otherwise it's equal to lastReplayedEndRecPtr.
+        */
+       XLogRecPtr      replayEndRecPtr;
+       TimeLineID      replayEndTLI;
+       /* timestamp of last COMMIT/ABORT record replayed (or being replayed) */
+       TimestampTz recoveryLastXTime;
+
+       /*
+        * timestamp of when we started replaying the current chunk of WAL data,
+        * only relevant for replication or archive recovery
+        */
+       TimestampTz currentChunkStartTime;
+       /* Recovery pause state */
+       RecoveryPauseState recoveryPauseState;
+       ConditionVariable recoveryNotPausedCV;
+
+       slock_t         info_lck;               /* locks shared variables shown above */
+} XLogRecoveryCtlData;
+
+extern PGDLLIMPORT XLogRecoveryCtlData *XLogRecoveryCtl;
+
 /* User-settable GUC parameters */
 extern PGDLLIMPORT bool recoveryTargetInclusive;
 extern PGDLLIMPORT int recoveryTargetAction;