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

Commit cdcdfca

Browse files
committed
Truncate the predicate lock SLRU to empty, instead of almost empty.
Otherwise, the SLRU machinery can get confused and think that the SLRU has wrapped around. Along the way, regardless of whether we're truncating all of the SLRU or just some of it, flush pages after truncating, rather than before. Kevin Grittner
1 parent 1766a5b commit cdcdfca

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/backend/storage/lmgr/predicate.c

+19-7
Original file line numberDiff line numberDiff line change
@@ -920,26 +920,38 @@ CheckPointPredicate(void)
920920
else
921921
{
922922
/*
923-
* The SLRU is no longer needed. Truncate everything but the last
924-
* page. We don't dare to touch the last page in case the SLRU is
925-
* taken back to use, and the new tail falls on the same page.
923+
* The SLRU is no longer needed. Truncate everything. If we try to
924+
* leave the head page around to avoid re-zeroing it, we might not
925+
* use the SLRU again until we're past the wrap-around point, which
926+
* makes SLRU unhappy.
927+
*
928+
* While the API asks you to specify truncation by page, it silently
929+
* ignores the request unless the specified page is in a segment
930+
* past some allocated portion of the SLRU. We don't care which
931+
* page in a later segment we hit, so just add the number of pages
932+
* per segment to the head page to land us *somewhere* in the next
933+
* segment.
926934
*/
927-
tailPage = oldSerXidControl->headPage;
935+
tailPage = oldSerXidControl->headPage + SLRU_PAGES_PER_SEGMENT;
928936
oldSerXidControl->headPage = -1;
929937
}
930938

931939
LWLockRelease(OldSerXidLock);
932940

941+
/* Truncate away pages that are no longer required */
942+
SimpleLruTruncate(OldSerXidSlruCtl, tailPage);
943+
933944
/*
934945
* Flush dirty SLRU pages to disk
935946
*
936947
* This is not actually necessary from a correctness point of view. We do
937948
* it merely as a debugging aid.
949+
*
950+
* We're doing this after the truncation to avoid writing pages right
951+
* before deleting the file in which they sit, which would be completely
952+
* pointless.
938953
*/
939954
SimpleLruFlush(OldSerXidSlruCtl, true);
940-
941-
/* Truncate away pages that are no longer required */
942-
SimpleLruTruncate(OldSerXidSlruCtl, tailPage);
943955
}
944956

945957
/*------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)