From cb2d481e680c54ec9805ddd02f4dc05df93485c1 Mon Sep 17 00:00:00 2001 From: quantumish Date: Fri, 25 Jul 2025 13:24:02 -0700 Subject: [PATCH] Make LFC resizing routine aware of invalid cache block entries --- .../neon/communicator/src/integrated_cache.rs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pgxn/neon/communicator/src/integrated_cache.rs b/pgxn/neon/communicator/src/integrated_cache.rs index 3464c786fe..4c3da29662 100644 --- a/pgxn/neon/communicator/src/integrated_cache.rs +++ b/pgxn/neon/communicator/src/integrated_cache.rs @@ -674,7 +674,7 @@ impl IntegratedCacheWriteAccess { } // Try and evict everything in to-be-shrinked space // TODO(quantumish): consider moving things ahead of clock hand? - let mut successful_evictions = 0; + let mut file_evictions = 0; for i in num_blocks..old_num_blocks { let Some(entry) = block_map.entry_at_bucket(i as usize) else { continue; @@ -693,9 +693,11 @@ impl IntegratedCacheWriteAccess { let cache_block = old.cache_block.swap(INVALID_CACHE_BLOCK, Ordering::Relaxed); entry.remove(); - file_cache.delete_block(cache_block); + if cache_block != INVALID_CACHE_BLOCK { + file_cache.delete_block(cache_block); + file_evictions += 1; + } - successful_evictions += 1; // TODO(quantumish): is this expected behavior? page_evictions.inc(); } @@ -704,10 +706,12 @@ impl IntegratedCacheWriteAccess { // an immediate-ish change in the file size, so we evict other entries to reclaim // enough space. Waiting for stragglers at the end of the map could *in theory* // take indefinite amounts of time depending on how long they stay pinned. - while successful_evictions < difference { + while file_evictions < difference { if let Some(i) = self.try_evict_one_cache_block() { - file_cache.delete_block(i); - successful_evictions += 1; + if i != INVALID_CACHE_BLOCK { + file_cache.delete_block(i); + file_evictions += 1; + } } } @@ -732,8 +736,10 @@ impl IntegratedCacheWriteAccess { _ = global_lw_lsn.fetch_max(old.lw_lsn.load().0, Ordering::Relaxed); let cache_block = old.cache_block.swap(INVALID_CACHE_BLOCK, Ordering::Relaxed); entry.remove(); - - file_cache.delete_block(cache_block); + + if cache_block != INVALID_CACHE_BLOCK { + file_cache.delete_block(cache_block); + } // TODO(quantumish): is this expected behavior? page_evictions.inc();