From ea63b43009f2ccac30e447de1095159365d27ad8 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Fri, 24 Nov 2023 08:23:00 +0200 Subject: [PATCH] Check if LFC was intialized in local_cache_pages function (#5911) ## Problem There is not check that LFC is initialised (`lfc_max_size != 0`) in `local_cache_pages` function ## Summary of changes Add proper check. ## Checklist before requesting a review - [ ] I have performed a self-review of my code. - [ ] If it is a core feature, I have added thorough tests. - [ ] Do we need to implement analytics? if so did you add the relevant metrics to the dashboard? - [ ] If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section. ## Checklist before merging - [ ] Do not forget to reformat commit message to not include the above checklist Co-authored-by: Konstantin Knizhnik --- pgxn/neon/file_cache.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index b28b95e42f..e70f0163c0 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -842,15 +842,18 @@ local_cache_pages(PG_FUNCTION_ARGS) fctx->tupdesc = BlessTupleDesc(tupledesc); - LWLockAcquire(lfc_lock, LW_SHARED); - - if (LFC_ENABLED()) + if (lfc_ctl) { - hash_seq_init(&status, lfc_hash); - while ((entry = hash_seq_search(&status)) != NULL) + LWLockAcquire(lfc_lock, LW_SHARED); + + if (LFC_ENABLED()) { - for (int i = 0; i < BLOCKS_PER_CHUNK/32; i++) - n_pages += pg_popcount32(entry->bitmap[i]); + hash_seq_init(&status, lfc_hash); + while ((entry = hash_seq_search(&status)) != NULL) + { + for (int i = 0; i < BLOCKS_PER_CHUNK/32; i++) + n_pages += pg_popcount32(entry->bitmap[i]); + } } } fctx->record = (LocalCachePagesRec *) @@ -891,7 +894,8 @@ local_cache_pages(PG_FUNCTION_ARGS) } Assert(n_pages == n); } - LWLockRelease(lfc_lock); + if (lfc_ctl) + LWLockRelease(lfc_lock); } funcctx = SRF_PERCALL_SETUP();