1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

Prevent excess SimpleLruTruncate() deletion.

Every core SLRU wraps around.  With the exception of pg_notify, the wrap
point can fall in the middle of a page.  Account for this in the
PagePrecedes callback specification and in SimpleLruTruncate()'s use of
said callback.  Update each callback implementation to fit the new
specification.  This changes SerialPagePrecedesLogically() from the
style of asyncQueuePagePrecedes() to the style of CLOGPagePrecedes().
(Whereas pg_clog and pg_serial share a key space, pg_serial is nothing
like pg_notify.)  The bug fixed here has the same symptoms and user
followup steps as 592a589a04.  Back-patch
to 9.5 (all supported versions).

Reviewed by Andrey Borodin and (in earlier versions) by Tom Lane.

Discussion: https://postgr.es/m/20190202083822.GC32531@gust.leadboat.com
This commit is contained in:
Noah Misch
2021-01-16 12:21:35 -08:00
parent c95765f476
commit 6db992833c
8 changed files with 313 additions and 79 deletions

View File

@ -490,7 +490,12 @@ asyncQueuePageDiff(int p, int q)
return diff;
}
/* Is p < q, accounting for wraparound? */
/*
* Is p < q, accounting for wraparound?
*
* Since asyncQueueIsFull() blocks creation of a page that could precede any
* extant page, we need not assess entries within a page.
*/
static bool
asyncQueuePagePrecedes(int p, int q)
{
@ -1352,8 +1357,8 @@ asyncQueueIsFull(void)
* logically precedes the current global tail pointer, ie, the head
* pointer would wrap around compared to the tail. We cannot create such
* a head page for fear of confusing slru.c. For safety we round the tail
* pointer back to a segment boundary (compare the truncation logic in
* asyncQueueAdvanceTail).
* pointer back to a segment boundary (truncation logic in
* asyncQueueAdvanceTail does not do this, so doing it here is optional).
*
* Note that this test is *not* dependent on how much space there is on
* the current head page. This is necessary because asyncQueueAddEntries