-
Notifications
You must be signed in to change notification settings - Fork 853
Add rel_size_replica_cache #11889
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
Add rel_size_replica_cache #11889
Conversation
8481 tests run: 7933 passed, 0 failed, 548 skipped (full report)Flaky tests (2)Postgres 17
Postgres 16
Code coverage* (full report)
* collected from Rust tests only The comment gets automatically updated with the latest test results
3735ab6 at 2025-05-20T14:51:15.151Z :recycle: |
VladLazar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea seems fine to me. I don't like that we are inferring the primary/replica status from the request_lsn, but that could go away with the communicator.
So the issue occurs when a non-primary endpoint updates the rel size cache, correct?
A regression test for that would be great. I still don't really see how that can happen.
There was a regress test proposed by @alexanderlaw in https://github.com/neondatabase/cloud/issues/28609 - not as simple as I preferred to have. But I failed to create simpler one. |
Yes. But it is not so easy to reproduce, because right now there is check in |
I think we should spend the time and check the test in. Best be sure we're actually fixing the issue. |
|
I did a quick check to see if the Alexander's test actually generates writes to relsize cache from static endpoints here. It does indeed. While working on that, I found out that the compute tells the pageserver of it's type: |
I do not think that using reported compute type is better approach. First of all because LSN range Also having range allows in principle to perform more precise check if cached LSN is valid. Finally, we are currently working on replica promotion. In this case endpoint type will be changed from replica to primary (without reconnect to PS). Yes, it can be somehow detected and handled. But why to worry about it if approach with LSN range handles it automatically? |
Promotion is a good point. LSN range is a basic concept on the compute side but that's not how people on the storage team think of requests. If it needs to change, then so be it, but at least let's use lsn range everywhere as suggested in #11889 (comment) |
VladLazar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Polite reminder: please check in Alexander's test. I know it's not as simple as we'd want it to be, but it reproduces the issue. You can take it from my PR if it makes it easier.
Done |
7dc7981 to
356eb40
Compare
|
I think, I can simplify the test if you're going to commit it. |
Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for going through my comments.
The only slightly substantial point I have is about checking the snapshot cache for the primary (see comment). The rest are nits for you to consider.
VladLazar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff!
Two final requests related to lock handling. Apologies for not spotting it earlier.
## Problem See Discussion: https://neondb.slack.com/archives/C033RQ5SPDH/p1746645666075799 Issue: neondatabase/neon-archive-cloud#28609 Relation size cache is not correctly updated at PS in case of replicas. ## Summary of changes 1. Have two caches for relation size in timeline: `rel_size_primary_cache` and `rel_size_replica_cache`. 2. `rel_size_primary_cache` is actually what we have now. The only difference is that it is not updated in `get_rel_size`, only by WAL ingestion 3. `rel_size_replica_cache` has limited size (LruCache) and it's key is `(Lsn,RelTag)` . It is updated in `get_rel_size`. Only strict LSN matches are accepted as cache hit. --------- Co-authored-by: Konstantin Knizhnik <knizhnik@neon.tech>
Problem
See
Discussion: https://neondb.slack.com/archives/C033RQ5SPDH/p1746645666075799
Issue: https://github.com/neondatabase/cloud/issues/28609
Relation size cache is not correctly updated at PS in case of replicas.
Summary of changes
rel_size_primary_cacheandrel_size_replica_cache.rel_size_primary_cacheis actually what we have now. The only difference is that it is not updated inget_rel_size, only by WAL ingestionrel_size_replica_cachehas limited size (LruCache) and it's key is(Lsn,RelTag). It is updated inget_rel_size. Only strict LSN matches are accepted as cache hit.