]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add assertion check for WAL receiver state during stream-archive transition
authorMichael Paquier <michael@paquier.xyz>
Tue, 4 Nov 2025 04:14:46 +0000 (13:14 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 4 Nov 2025 04:14:46 +0000 (13:14 +0900)
When the startup process switches from streaming to archive as WAL
source, we avoid calling ShutdownWalRcv() if the WAL receiver is not
streaming, based on WalRcvStreaming().  WALRCV_STOPPING is a state set
by ShutdownWalRcv(), called only by the startup process, meaning that it
should not be possible to reach this state while in
WaitForWALToBecomeAvailable().

This commit adds an assertion to make sure that a WAL receiver is never
in a WALRCV_STOPPING state should the startup process attempt to reset
InstallXLogFileSegmentActive.

Idea suggested by Noah Misch.

Author: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/19093-c4fff49a608f82a0@postgresql.org

src/backend/access/transam/xlogrecovery.c

index cb62d43077d6d2534b984bae169a1437e874ffed..0a5ae5050c461d2b2ee2fdef84e6872fbacfae5e 100644 (file)
@@ -3698,6 +3698,14 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
                                                XLogShutdownWalRcv();
                                        else
                                        {
+                                               /*
+                                                * WALRCV_STOPPING state is a transient state while
+                                                * the startup process is in ShutdownWalRcv().  It
+                                                * should never appear here since we would be waiting
+                                                * for the walreceiver to reach WALRCV_STOPPED in that
+                                                * case.
+                                                */
+                                               Assert(WalRcvGetState() != WALRCV_STOPPING);
                                                ResetInstallXLogFileSegmentActive();
                                        }