Skip to content

Commit d6b0c2b

Browse files
committed
Improve truncation of pg_serial/, removing "apparent wraparound" LOGs
It is possible that the tail XID of pg_serial/ gets ahead of its head XID, which would cause the truncation of pg_serial/ done during checkpoints to show up as a "wraparound" LOG in SimpleLruTruncate(), which is confusing. This also wastes a bit of disk space until the head page is reclaimed again. CheckPointPredicate() is changed so as the cutoff page for the truncation is switched to the head page if the tail XID has advanced beyond the head XID, rather than the tail page. This prevents the confusing LOG message about a wraparound while allowing some truncation to be done to cut in disk space. This could be considered as a bug fix, but the original behavior is harmless as well, resulting only in disk space temporarily wasted, so no backpatch is done. Author: Sami Imseih Reviewed-by: Heikki Linnakangas, Michael Paquier Discussion: https://postgr.es/m/755E19CA-D02C-4A4C-80D3-74F775410C48@amazon.com
1 parent 6fcaeb0 commit d6b0c2b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/backend/storage/lmgr/predicate.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ SerialSetActiveSerXmin(TransactionId xid)
10041004
void
10051005
CheckPointPredicate(void)
10061006
{
1007-
int tailPage;
1007+
int truncateCutoffPage;
10081008

10091009
LWLockAcquire(SerialSLRULock, LW_EXCLUSIVE);
10101010

@@ -1017,8 +1017,24 @@ CheckPointPredicate(void)
10171017

10181018
if (TransactionIdIsValid(serialControl->tailXid))
10191019
{
1020-
/* We can truncate the SLRU up to the page containing tailXid */
1020+
int tailPage;
1021+
10211022
tailPage = SerialPage(serialControl->tailXid);
1023+
1024+
/*
1025+
* It is possible for the tailXid to be ahead of the headXid. This
1026+
* occurs if we checkpoint while there are in-progress serializable
1027+
* transaction(s) advancing the tail but we are yet to summarize the
1028+
* transactions. In this case, we cutoff up to the headPage and the
1029+
* next summary will advance the headXid.
1030+
*/
1031+
if (SerialPagePrecedesLogically(tailPage, serialControl->headPage))
1032+
{
1033+
/* We can truncate the SLRU up to the page containing tailXid */
1034+
truncateCutoffPage = tailPage;
1035+
}
1036+
else
1037+
truncateCutoffPage = serialControl->headPage;
10221038
}
10231039
else
10241040
{
@@ -1051,14 +1067,14 @@ CheckPointPredicate(void)
10511067
* transaction instigating the summarize fails in
10521068
* SimpleLruReadPage().
10531069
*/
1054-
tailPage = serialControl->headPage;
1070+
truncateCutoffPage = serialControl->headPage;
10551071
serialControl->headPage = -1;
10561072
}
10571073

10581074
LWLockRelease(SerialSLRULock);
10591075

10601076
/* Truncate away pages that are no longer required */
1061-
SimpleLruTruncate(SerialSlruCtl, tailPage);
1077+
SimpleLruTruncate(SerialSlruCtl, truncateCutoffPage);
10621078

10631079
/*
10641080
* Write dirty SLRU pages to disk

0 commit comments

Comments
 (0)