Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb755133

Browse files
committed
Fix off-by-one error in calculating subtrans/multixact truncation point.
If there were no subtransactions (or multixacts) active, we would calculatethe oldestxid == next xid. That's correct, but if next XID happens to beon the next pg_subtrans (pg_multixact) page, the page does not exist yet,and SimpleLruTruncate will produce an "apparent wraparound" warning. Thewarning is harmless in this case, but looks very alarming to users.Backpatch to all supported versions. Patch and analysis by Thomas Munro.
1 parentb6e7780 commitb755133

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

‎src/backend/access/transam/multixact.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@
171171
#defineMULTIXACT_MEMBER_DANGER_THRESHOLD\
172172
(MaxMultiXactOffset - MaxMultiXactOffset / 4)
173173

174+
#definePreviousMultiXactId(xid) \
175+
((xid) == FirstMultiXactId ? MaxMultiXactId : (xid) - 1)
174176

175177
/*
176178
* Links to shared-memory data structures for MultiXact control
@@ -3076,9 +3078,15 @@ TruncateMultiXact(void)
30763078

30773079
SlruScanDirectory(MultiXactMemberCtl,SlruScanDirCbRemoveMembers,&range);
30783080

3079-
/* Now we can truncate MultiXactOffset */
3081+
/*
3082+
* Now we can truncate MultiXactOffset. We step back one multixact to
3083+
* avoid passing a cutoff page that hasn't been created yet in the rare
3084+
* case that oldestMXact would be the first item on a page and oldestMXact
3085+
* == nextMXact. In that case, if we didn't subtract one, we'd trigger
3086+
* SimpleLruTruncate's wraparound detection.
3087+
*/
30803088
SimpleLruTruncate(MultiXactOffsetCtl,
3081-
MultiXactIdToOffsetPage(oldestMXact));
3089+
MultiXactIdToOffsetPage(PreviousMultiXactId(oldestMXact)));
30823090

30833091
/*
30843092
* Now, and only now, we can advance the stop point for multixact members.

‎src/backend/access/transam/subtrans.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,13 @@ TruncateSUBTRANS(TransactionId oldestXact)
340340

341341
/*
342342
* The cutoff point is the start of the segment containing oldestXact. We
343-
* pass the *page* containing oldestXact to SimpleLruTruncate.
343+
* pass the *page* containing oldestXact to SimpleLruTruncate. We step
344+
* back one transaction to avoid passing a cutoff page that hasn't been
345+
* created yet in the rare case that oldestXact would be the first item on
346+
* a page and oldestXact == next XID. In that case, if we didn't subtract
347+
* one, we'd trigger SimpleLruTruncate's wraparound detection.
344348
*/
349+
TransactionIdRetreat(oldestXact);
345350
cutoffPage=TransactionIdToPage(oldestXact);
346351

347352
SimpleLruTruncate(SubTransCtl,cutoffPage);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp