From a2a21524661c43955b799323295bec40e9cd3323 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 19 Mar 2026 17:21:30 +0200 Subject: [PATCH v20260405 08/15] refactor predicate.c: inline SerialInit to the caller The ShmemInit function is very complicated currently. These refactorings move it in a direction that is more natural with the new shmem callbacks. --- src/backend/storage/lmgr/predicate.c | 73 +++++++++++----------------- 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c index e003fa5b107..13a6a4b93a6 100644 --- a/src/backend/storage/lmgr/predicate.c +++ b/src/backend/storage/lmgr/predicate.c @@ -444,7 +444,6 @@ static void FlagSxactUnsafe(SERIALIZABLEXACT *sxact); static bool SerialPagePrecedesLogically(int64 page1, int64 page2); static int serial_errdetail_for_io_error(const void *opaque_data); -static void SerialInit(void); static void SerialAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo); static SerCommitSeqNo SerialGetMinConflictCommitSeqNo(TransactionId xid); static void SerialSetActiveSerXmin(TransactionId xid); @@ -809,48 +808,6 @@ SerialPagePrecedesLogicallyUnitTests(void) } #endif -/* - * Initialize for the tracking of old serializable committed xids. - */ -static void -SerialInit(void) -{ - bool found; - - /* - * Set up SLRU management of the pg_serial data. - */ - SerialSlruCtl->PagePrecedes = SerialPagePrecedesLogically; - SerialSlruCtl->errdetail_for_io_error = serial_errdetail_for_io_error; - SimpleLruInit(SerialSlruCtl, "serializable", - serializable_buffers, 0, "pg_serial", - LWTRANCHE_SERIAL_BUFFER, LWTRANCHE_SERIAL_SLRU, - SYNC_HANDLER_NONE, false); -#ifdef USE_ASSERT_CHECKING - SerialPagePrecedesLogicallyUnitTests(); -#endif - SlruPagePrecedesUnitTests(SerialSlruCtl, SERIAL_ENTRIESPERPAGE); - - /* - * Create or attach to the SerialControl structure. - */ - serialControl = (SerialControl) - ShmemInitStruct("SerialControlData", sizeof(SerialControlData), &found); - - Assert(found == IsUnderPostmaster); - if (!found) - { - /* - * Set control information to reflect empty SLRU. - */ - LWLockAcquire(SerialControlLock, LW_EXCLUSIVE); - serialControl->headPage = -1; - serialControl->headXid = InvalidTransactionId; - serialControl->tailXid = InvalidTransactionId; - LWLockRelease(SerialControlLock); - } -} - /* * GUC check_hook for serializable_buffers */ @@ -1355,7 +1312,35 @@ PredicateLockShmemInit(void) * Initialize the SLRU storage for old committed serializable * transactions. */ - SerialInit(); + SerialSlruCtl->PagePrecedes = SerialPagePrecedesLogically; + SerialSlruCtl->errdetail_for_io_error = serial_errdetail_for_io_error; + SimpleLruInit(SerialSlruCtl, "serializable", + serializable_buffers, 0, "pg_serial", + LWTRANCHE_SERIAL_BUFFER, LWTRANCHE_SERIAL_SLRU, + SYNC_HANDLER_NONE, false); +#ifdef USE_ASSERT_CHECKING + SerialPagePrecedesLogicallyUnitTests(); +#endif + SlruPagePrecedesUnitTests(SerialSlruCtl, SERIAL_ENTRIESPERPAGE); + + /* + * Create or attach to the SerialControl structure. + */ + serialControl = (SerialControl) + ShmemInitStruct("SerialControlData", sizeof(SerialControlData), &found); + + Assert(found == IsUnderPostmaster); + if (!found) + { + /* + * Set control information to reflect empty SLRU. + */ + LWLockAcquire(SerialControlLock, LW_EXCLUSIVE); + serialControl->headPage = -1; + serialControl->headXid = InvalidTransactionId; + serialControl->tailXid = InvalidTransactionId; + LWLockRelease(SerialControlLock); + } } /* -- 2.34.1