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

Commit 312747c

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 1a8a4e5 commit 312747c

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
@@ -2492,13 +2492,24 @@ DetermineSafeOldestOffset(MultiXactId oldestMXact)
24922492
return;
24932493

24942494
/*
2495-
* We determine the safe upper bound for offsets of new xacts by reading
2496-
* the offset of the oldest multixact, and going back one segment. This
2497-
* way, the sequence of multixact member segments will always have a
2498-
* one-segment hole at a minimum. We start spewing warnings a few
2499-
* complete segments before that.
2495+
* Determine the offset of the oldest multixact. Normally, we can read
2496+
* the offset from the multixact itself, but there's an important special
2497+
* case: if there are no multixacts in existence at all, oldestMXact
2498+
* obviously can't point to one. It will instead point to the multixact
2499+
* ID that will be assigned the next time one is needed.
25002500
*/
2501-
oldestOffset = find_multixact_start(oldestMXact);
2501+
LWLockAcquire(MultiXactGenLock, LW_SHARED);
2502+
if (MultiXactState->nextMXact == oldestMXact)
2503+
{
2504+
oldestOffset = MultiXactState->nextOffset;
2505+
LWLockRelease(MultiXactGenLock);
2506+
}
2507+
else
2508+
{
2509+
LWLockRelease(MultiXactGenLock);
2510+
oldestOffset = find_multixact_start(oldestMXact);
2511+
}
2512+
25022513
/* move back to start of the corresponding segment */
25032514
oldestOffset -= oldestOffset %
25042515
(MULTIXACT_MEMBERS_PER_PAGE * SLRU_PAGES_PER_SEGMENT);

0 commit comments

Comments
 (0)