From fb1957936ccfd4299f1e7912f6024470249721c2 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Mon, 10 Mar 2025 20:28:55 +0200 Subject: [PATCH] Fix caclulation of LFC used_pages (#11095) ## Problem Async prefetch in LFC PR cause incorrect calculation of LFC `used_pages`when page is overwritten ## Summary of changes Decrement `used_pages` is page is overwritten. --------- Co-authored-by: Konstantin Knizhnik Co-authored-by: Matthias van de Meent --- pgxn/neon/file_cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index 9f0a877b07..f13522e55b 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -1195,9 +1195,11 @@ lfc_writev(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, state = GET_STATE(entry, chunk_offs + i); if (state == PENDING) { SET_STATE(entry, chunk_offs + i, REQUESTED); - } else if (state != REQUESTED) { + } else if (state == UNAVAILABLE) { SET_STATE(entry, chunk_offs + i, PENDING); break; + } else if (state == AVAILABLE) { + break; } if (!sleeping) {