Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix bug in SetOffsetVacuumLimit() triggered by find_multixact_start() failure.
authorAndres Freund <andres@anarazel.de>
Mon, 14 Dec 2015 10:34:16 +0000 (11:34 +0100)
committerAndres Freund <andres@anarazel.de>
Mon, 14 Dec 2015 10:34:50 +0000 (11:34 +0100)
Previously, if find_multixact_start() failed, SetOffsetVacuumLimit() would
install 0 into MultiXactState->offsetStopLimit if it previously succeeded.
Luckily, there are no known cases where find_multixact_start() will return
an error in 9.5 and above. But if it were to happen, for example due to
filesystem permission issues, it'd be somewhat bad: GetNewMultiXactId()
could continue allocating mxids even if close to a wraparound, or it could
erroneously stop allocating mxids, even if no wraparound is looming.  The
wrong value would be corrected the next time SetOffsetVacuumLimit() is
called, or by a restart.

Reported-By: Noah Misch, although this is not his preferred fix
Discussion: 20151210140450.GA22278@alap3.anarazel.de
Backpatch: 9.5, where the bug was introduced as part of 4f627f

src/backend/access/transam/multixact.c

index c886ec32284bae3e5bd43ea21d40f15a7c68ea1f..c730fc49c50bd77072bf8752da7c2fcf93ad85d6 100644 (file)
@@ -2552,6 +2552,7 @@ SetOffsetVacuumLimit(void)
    bool        oldestOffsetKnown = false;
    bool        prevOldestOffsetKnown;
    MultiXactOffset offsetStopLimit = 0;
+   MultiXactOffset prevOffsetStopLimit;
 
    /*
     * NB: Have to prevent concurrent truncation, we might otherwise try to
@@ -2566,6 +2567,7 @@ SetOffsetVacuumLimit(void)
    nextOffset = MultiXactState->nextOffset;
    prevOldestOffsetKnown = MultiXactState->oldestOffsetKnown;
    prevOldestOffset = MultiXactState->oldestOffset;
+   prevOffsetStopLimit = MultiXactState->offsetStopLimit;
    Assert(MultiXactState->finishedStartup);
    LWLockRelease(MultiXactGenLock);
 
@@ -2633,11 +2635,13 @@ SetOffsetVacuumLimit(void)
    {
        /*
         * If we failed to get the oldest offset this time, but we have a
-        * value from a previous pass through this function, use the old value
-        * rather than automatically forcing it.
+        * value from a previous pass through this function, use the old
+        * values rather than automatically forcing an emergency autovacuum
+        * cycle again.
         */
        oldestOffset = prevOldestOffset;
        oldestOffsetKnown = true;
+       offsetStopLimit = prevOffsetStopLimit;
    }
 
    /* Install the computed values */