-
Notifications
You must be signed in to change notification settings - Fork 189
fix: size calculation for zstd frame cache #5859
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
141f578
fix: size calculation for zstd frame cache
hanabi1224 2cdded9
use SizeTrackingLruCache
hanabi1224 6235c17
change ZSTD_FRAME_CACHE_DEFAULT_MAX_SIZE to 256MiB
hanabi1224 fec0565
Update src/db/car/mod.rs
hanabi1224 af64c74
Merge remote-tracking branch 'origin/main' into hm/fix-zstd-frame-cac…
hanabi1224 297605a
unit test
hanabi1224 ce81151
Merge remote-tracking branch 'origin/main' into hm/fix-zstd-frame-cac…
hanabi1224 56bdcf4
changelog
hanabi1224 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,3 +117,4 @@ V0 | |
| V1 | ||
| VPS | ||
| WIP | ||
| zstd | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,19 +59,29 @@ where | |
| registry.register_collector(Box::new(self.clone())); | ||
| } | ||
|
|
||
| pub fn new_without_metrics_registry( | ||
| cache_name: Cow<'static, str>, | ||
| capacity: NonZeroUsize, | ||
| ) -> Self { | ||
| fn new_inner(cache_name: Cow<'static, str>, capacity: Option<NonZeroUsize>) -> Self { | ||
| static ID_GENERATOR: AtomicUsize = AtomicUsize::new(0); | ||
|
|
||
| Self { | ||
| cache_id: ID_GENERATOR.fetch_add(1, Ordering::Relaxed), | ||
| cache_name, | ||
| cache: Arc::new(RwLock::new(LruCache::new(capacity))), | ||
| #[allow(clippy::disallowed_methods)] | ||
| cache: Arc::new(RwLock::new( | ||
| capacity | ||
| .map(LruCache::new) | ||
| // For constructing lru cache that is bounded by memory usage instead of length | ||
| .unwrap_or_else(LruCache::unbounded), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we ban the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
| )), | ||
| } | ||
| } | ||
|
|
||
| pub fn new_without_metrics_registry( | ||
| cache_name: Cow<'static, str>, | ||
| capacity: NonZeroUsize, | ||
| ) -> Self { | ||
| Self::new_inner(cache_name, Some(capacity)) | ||
| } | ||
|
|
||
| pub fn new_with_metrics_registry( | ||
| cache_name: Cow<'static, str>, | ||
| capacity: NonZeroUsize, | ||
|
|
@@ -89,6 +99,23 @@ where | |
| Self::new_with_metrics_registry(cache_name, capacity, &mut default_registry()) | ||
| } | ||
|
|
||
| pub fn unbounded_without_metrics_registry(cache_name: Cow<'static, str>) -> Self { | ||
| Self::new_inner(cache_name, None) | ||
| } | ||
|
|
||
| pub fn unbounded_with_metrics_registry( | ||
| cache_name: Cow<'static, str>, | ||
| metrics_registry: &mut Registry, | ||
| ) -> Self { | ||
| let c = Self::unbounded_without_metrics_registry(cache_name); | ||
| c.register_metrics(metrics_registry); | ||
| c | ||
| } | ||
|
|
||
| pub fn unbounded_with_default_metrics_registry(cache_name: Cow<'static, str>) -> Self { | ||
| Self::unbounded_with_metrics_registry(cache_name, &mut default_registry()) | ||
| } | ||
|
|
||
| pub fn cache(&self) -> &Arc<RwLock<LruCache<K, V>>> { | ||
| &self.cache | ||
| } | ||
|
|
@@ -113,6 +140,10 @@ where | |
| self.cache.read().peek(k).cloned() | ||
| } | ||
|
|
||
| pub fn pop_lru(&self) -> Option<(K, V)> { | ||
| self.cache.write().pop_lru() | ||
| } | ||
|
|
||
| pub fn len(&self) -> usize { | ||
| self.cache.read().len() | ||
| } | ||
|
|
@@ -121,7 +152,7 @@ where | |
| self.cache.read().cap().get() | ||
| } | ||
|
|
||
| fn size_in_bytes(&self) -> usize { | ||
| pub(crate) fn size_in_bytes(&self) -> usize { | ||
| let mut size = 0_usize; | ||
| for (k, v) in self.cache.read().iter() { | ||
| size = size | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd love it if we could have some coverage here, both on the logic level and size calculation correctness.
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.
Fixed.