Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7b3f0f8

Browse files
committed
Fix DetermineSafeOldestOffset for the case where there are no mxacts.
Commit b69bf30 failed to take into account the possibility that there might be no multixacts in existence at all. Report by Thomas Munro; patch by me.
1 parent c106f39 commit 7b3f0f8

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/backend/access/transam/multixact.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,13 +2511,24 @@ DetermineSafeOldestOffset(MultiXactId oldestMXact)
25112511
return;
25122512

25132513
/*
2514-
* We determine the safe upper bound for offsets of new xacts by reading
2515-
* the offset of the oldest multixact, and going back one segment. This
2516-
* way, the sequence of multixact member segments will always have a
2517-
* one-segment hole at a minimum. We start spewing warnings a few
2518-
* complete segments before that.
2514+
* Determine the offset of the oldest multixact. Normally, we can read
2515+
* the offset from the multixact itself, but there's an important special
2516+
* case: if there are no multixacts in existence at all, oldestMXact
2517+
* obviously can't point to one. It will instead point to the multixact
2518+
* ID that will be assigned the next time one is needed.
25192519
*/
2520-
oldestOffset = find_multixact_start(oldestMXact);
2520+
LWLockAcquire(MultiXactGenLock, LW_SHARED);
2521+
if (MultiXactState->nextMXact == oldestMXact)
2522+
{
2523+
oldestOffset = MultiXactState->nextOffset;
2524+
LWLockRelease(MultiXactGenLock);
2525+
}
2526+
else
2527+
{
2528+
LWLockRelease(MultiXactGenLock);
2529+
oldestOffset = find_multixact_start(oldestMXact);
2530+
}
2531+
25212532
/* move back to start of the corresponding segment */
25222533
oldestOffset -= oldestOffset %
25232534
(MULTIXACT_MEMBERS_PER_PAGE * SLRU_PAGES_PER_SEGMENT);

0 commit comments

Comments
 (0)