Change GetMultiXactInfo() to return the next multixact offset
authorMichael Paquier <michael@paquier.xyz>
Tue, 30 Dec 2025 05:03:49 +0000 (14:03 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 30 Dec 2025 05:03:49 +0000 (14:03 +0900)
This routine returned a number of members as a MultiXactOffset,
calculated based on the difference between the next-to-be-assigned
offset and the oldest offset.  However, this number is not actually an
offset but a number.

This type confusion comes from the original implementation of
MultiXactMemberFreezeThreshold(), in 53bb309d2d5a.  The number of
members is now defined as a uint64, large enough for MultiXactOffset.
This change will be used in a follow-up patch.

Reviewed-by: Naga Appani <nagnrik@gmail.com>
Discussion: https://postgr.es/m/aUyTvZMq2CLgNEB4@paquier.xyz

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

index 34956a5a6634a82194a1127b3bf67fac4a55ee75..0d6f594e2a06c513881719e8152343d6e5dba13e 100644 (file)
@@ -2461,25 +2461,23 @@ find_multixact_start(MultiXactId multi, MultiXactOffset *result)
  *
  * Returns information about the current MultiXact state, as of:
  * multixacts: Number of MultiXacts (nextMultiXactId - oldestMultiXactId)
- * members: Number of member entries (nextOffset - oldestOffset)
+ * nextOffset: Next-to-be-assigned offset
  * oldestMultiXactId: Oldest MultiXact ID still in use
  * oldestOffset: Oldest offset still in use
  */
 void
-GetMultiXactInfo(uint32 *multixacts, MultiXactOffset *members,
+GetMultiXactInfo(uint32 *multixacts, MultiXactOffset *nextOffset,
                 MultiXactId *oldestMultiXactId, MultiXactOffset *oldestOffset)
 {
-   MultiXactOffset nextOffset;
    MultiXactId nextMultiXactId;
 
    LWLockAcquire(MultiXactGenLock, LW_SHARED);
-   nextOffset = MultiXactState->nextOffset;
+   *nextOffset = MultiXactState->nextOffset;
    *oldestMultiXactId = MultiXactState->oldestMultiXactId;
    nextMultiXactId = MultiXactState->nextMXact;
    *oldestOffset = MultiXactState->oldestOffset;
    LWLockRelease(MultiXactGenLock);
 
-   *members = nextOffset - *oldestOffset;
    *multixacts = nextMultiXactId - *oldestMultiXactId;
 }
 
@@ -2514,16 +2512,18 @@ GetMultiXactInfo(uint32 *multixacts, MultiXactOffset *members,
 int
 MultiXactMemberFreezeThreshold(void)
 {
-   MultiXactOffset members;
    uint32      multixacts;
    uint32      victim_multixacts;
    double      fraction;
    int         result;
    MultiXactId oldestMultiXactId;
    MultiXactOffset oldestOffset;
+   MultiXactOffset nextOffset;
+   uint64      members;
 
-   /* Read the current offsets and members usage. */
-   GetMultiXactInfo(&multixacts, &members, &oldestMultiXactId, &oldestOffset);
+   /* Read the current offsets and multixact usage. */
+   GetMultiXactInfo(&multixacts, &nextOffset, &oldestMultiXactId, &oldestOffset);
+   members = nextOffset - oldestOffset;
 
    /* If member space utilization is low, no special action is required. */
    if (members <= MULTIXACT_MEMBER_LOW_THRESHOLD)
index 6433fe163641ea1d9e434af86f6753e4811afefa..d22abbb72512943b8b2c6989c37b3fa052e0749c 100644 (file)
@@ -109,7 +109,7 @@ extern bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly);
 extern void MultiXactIdSetOldestMember(void);
 extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
                                  bool from_pgupgrade, bool isLockOnly);
-extern void GetMultiXactInfo(uint32 *multixacts, MultiXactOffset *members,
+extern void GetMultiXactInfo(uint32 *multixacts, MultiXactOffset *nextOffset,
                             MultiXactId *oldestMultiXactId,
                             MultiXactOffset *oldestOffset);
 extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);