From 47c3c9a4134d76215794b49c5e8dbb1580730934 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Mon, 7 Oct 2024 12:21:16 +0300 Subject: [PATCH] Fix update of statistic for LFC/prefetch (#9272) ## Problem See #9199 ## Summary of changes Fix update of hits/misses for LFC and prefetch introduced in https://github.com/neondatabase/neon/commit/78938d1b591b33d23495a0edb8b123cc5cac6a27 ## 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/pagestore_smgr.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pgxn/neon/pagestore_smgr.c b/pgxn/neon/pagestore_smgr.c index 155756f8b3..08b3b53f02 100644 --- a/pgxn/neon/pagestore_smgr.c +++ b/pgxn/neon/pagestore_smgr.c @@ -886,12 +886,19 @@ Retry: { min_ring_index = Min(min_ring_index, ring_index); /* The buffered request is good enough, return that index */ - pgBufferUsage.prefetch.duplicates++; + if (is_prefetch) + pgBufferUsage.prefetch.duplicates++; + else + pgBufferUsage.prefetch.hits++; continue; } } } - + else if (!is_prefetch) + { + pgBufferUsage.prefetch.misses += 1; + MyNeonCounters->getpage_prefetch_misses_total++; + } /* * We can only leave the block above by finding that there's * no entry that can satisfy this request, either because there @@ -2797,7 +2804,6 @@ Retry: if (neon_prefetch_response_usable(reqlsns, slot)) { ring_index = slot->my_ring_index; - pgBufferUsage.prefetch.hits += 1; } else { @@ -2827,9 +2833,6 @@ Retry: { if (entry == NULL) { - pgBufferUsage.prefetch.misses += 1; - MyNeonCounters->getpage_prefetch_misses_total++; - ring_index = prefetch_register_bufferv(buftag, reqlsns, 1, NULL, false); Assert(ring_index != UINT64_MAX); slot = GetPrfSlot(ring_index); @@ -3059,6 +3062,9 @@ neon_readv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, lfc_result = lfc_readv_select(InfoFromSMgrRel(reln), forknum, blocknum, buffers, nblocks, read); + if (lfc_result > 0) + MyNeonCounters->file_cache_hits_total += lfc_result; + /* Read all blocks from LFC, so we're done */ if (lfc_result == nblocks) return;