Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in lfc_cache_containsv #10672

Closed
wants to merge 2 commits into from
Closed

Fix bugs in lfc_cache_containsv #10672

wants to merge 2 commits into from

Conversation

knizhnik
Copy link
Contributor

@knizhnik knizhnik commented Feb 5, 2025

Problem

I have found one problem and two bugs in current LFC implementation.

  1. If LFC is intentionally disabled by setting neon.file_cache_size_limit=0 then it can not be reenabled, because lfc_change_limit_hook immediately exit if !lfc_ensure_opened()) and it is true in case of neon.file_cache_size_limit=0.
  2. I believe that there are two bugs in lfc_cache_containsv (and so affecting only pg17).

Summary of changes

  1. Remove lfc_maybe_disabled check from lfc_ensure_opened
-		int		this_chunk = Min(nblocks, BLOCKS_PER_CHUNK - chunk_offs);
+		int		this_chunk = Min(nblocks - i, BLOCKS_PER_CHUNK - chunk_offs);		int		this_chunk = ```
-		if (i + 1 >= nblocks)
+		if (i >= nblocks)

@knizhnik knizhnik requested review from a team as code owners February 5, 2025 15:55
@hlinnaka
Copy link
Contributor

hlinnaka commented Feb 5, 2025

Can you split this into two PRs, please? Or even three, if the two fixed in lfc_cache_containsv` are easy to separate.

Tests would be good.

/* Open cache file if not done yet */
if (lfc_desc <= 0 && enabled)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be opening the LFC file if we've disabled the LFC.

-1 on this change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I think we really need to be able to reenable LFC.
I have added the following check to make sure that we open LFC file only if LFC was enabled or we are going to reenable it:

	/* Open LFC file only if LFC was  enabled or we are going to reenable it */
	if ((newval > 0 || LFC_ENABLED()) && !lfc_ensure_opened())
		return;

tag.blockNum = (blkno + i) & ~(BLOCKS_PER_CHUNK - 1);
tag.blockNum = blkno & ~(BLOCKS_PER_CHUNK - 1);
hash = get_hash_value(lfc_hash, &tag);
chunk_offs = (blkno + i) & (BLOCKS_PER_CHUNK - 1);
chunk_offs = blkno & (BLOCKS_PER_CHUNK - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really a bug getting fixed here, but alright.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is certainly not a bug, just some code simplification.

while (true)
{
int this_chunk = Min(nblocks, BLOCKS_PER_CHUNK - chunk_offs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's a bug indeed, when crossing chunk boundaries. I'm not sure though why all those other things needed changing, IIUC those worked just fine.

Copy link

github-actions bot commented Feb 5, 2025

7425 tests run: 7072 passed, 0 failed, 353 skipped (full report)


Code coverage* (full report)

  • functions: 33.2% (8575 of 25805 functions)
  • lines: 49.1% (72139 of 147055 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
3e8faa8 at 2025-02-05T20:01:16.477Z :recycle:

@knizhnik
Copy link
Contributor Author

knizhnik commented Feb 5, 2025

Can you split this into two PRs, please? Or even three, if the two fixed in lfc_cache_containsv` are easy to separate.

Tests would be good.

#10681
#10682
#10683

@knizhnik
Copy link
Contributor Author

knizhnik commented Feb 6, 2025

Spitted into 3 PRs:
#10681
#10682
#10683

@knizhnik knizhnik closed this Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants