#define MULTIXACT_MEMBER_DANGER_THRESHOLD \
(MaxMultiXactOffset - MaxMultiXactOffset / 4)
+#define PreviousMultiXactId(xid) \
+ ((xid) == FirstMultiXactId ? MaxMultiXactId : (xid) - 1)
/*
* Links to shared-memory data structures for MultiXact control
SlruScanDirectory(MultiXactMemberCtl, SlruScanDirCbRemoveMembers, &range);
- /* Now we can truncate MultiXactOffset */
+ /*
+ * Now we can truncate MultiXactOffset. We step back one multixact to
+ * avoid passing a cutoff page that hasn't been created yet in the rare
+ * case that oldestMXact would be the first item on a page and oldestMXact
+ * == nextMXact. In that case, if we didn't subtract one, we'd trigger
+ * SimpleLruTruncate's wraparound detection.
+ */
SimpleLruTruncate(MultiXactOffsetCtl,
- MultiXactIdToOffsetPage(oldestMXact));
-
+ MultiXactIdToOffsetPage(PreviousMultiXactId(oldestMXact)));
/*
* Now, and only now, we can advance the stop point for multixact members.
/*
* The cutoff point is the start of the segment containing oldestXact. We
- * pass the *page* containing oldestXact to SimpleLruTruncate.
+ * pass the *page* containing oldestXact to SimpleLruTruncate. We step
+ * back one transaction to avoid passing a cutoff page that hasn't been
+ * created yet in the rare case that oldestXact would be the first item on
+ * a page and oldestXact == next XID. In that case, if we didn't subtract
+ * one, we'd trigger SimpleLruTruncate's wraparound detection.
*/
+ TransactionIdRetreat(oldestXact);
cutoffPage = TransactionIdToPage(oldestXact);
SimpleLruTruncate(SubTransCtl, cutoffPage);