-
Notifications
You must be signed in to change notification settings - Fork 0
Ram only mode for liquid cache #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,7 +302,9 @@ impl LiquidCache { | |
| } | ||
| } | ||
|
|
||
| /// Insert a batch into the cache, it will run cache replacement policy until the batch is inserted. | ||
| /// Insert a batch into the cache. RAM-only: when full, evict the LRU | ||
| /// victim by dropping it; never spill to disk. If the new entry doesn't | ||
| /// fit even after the cache is empty, silently skip caching it. | ||
| pub(crate) async fn insert_inner(&self, entry_id: EntryID, mut batch_to_cache: CacheEntry) { | ||
| loop { | ||
| let Err(not_inserted) = self.try_insert(entry_id, batch_to_cache) else { | ||
|
|
@@ -313,24 +315,28 @@ impl LiquidCache { | |
| kind: CachedBatchType::from(¬_inserted), | ||
| }); | ||
|
|
||
| let victims = self.cache_policy.find_victim(8); | ||
| // Evict one victim per iteration: dropped data can't come back, so | ||
| // over-eviction would silently discard recently-used entries. | ||
| let victims = self.cache_policy.find_victim(1); | ||
| if victims.is_empty() { | ||
| // no advice, because the cache is already empty | ||
| // this can happen if the entry to be inserted is too large, in that case, | ||
| // we write it to disk | ||
| let on_disk_batch = self | ||
| .write_in_memory_batch_to_disk(entry_id, not_inserted) | ||
| .await; | ||
| batch_to_cache = on_disk_batch; | ||
| continue; | ||
| // Nothing left to free; the entry is larger than the budget. | ||
| return; | ||
| } | ||
| self.squeeze_victims(victims).await; | ||
|
|
||
| self.drop_victims(&victims); | ||
| batch_to_cache = not_inserted; | ||
| crate::utils::yield_now_if_shuttle(); | ||
| } | ||
| } | ||
|
|
||
| fn drop_victims(&self, victims: &[EntryID]) { | ||
|
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. nit: (not blocking) with the new RAM-only insert path, several pieces of code are no longer reachable: |
||
| for victim in victims { | ||
| self.trace(InternalEvent::SqueezeVictim { entry: *victim }); | ||
|
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. super nit: (not blocking) the trace event is still |
||
| if let Some(entry) = self.index.remove(victim) { | ||
| self.budget.release_memory(entry.memory_usage_bytes()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Create a new instance of CacheStorage. | ||
| pub(crate) fn new( | ||
| batch_size: usize, | ||
|
|
||
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.
Two existing tests assume the now-removed squeeze/spill path and will fail under this change:
src/core/src/cache/core.rs:982(test_cache_advice_strategies) doesstore.index().get(&entry_id1).unwrap()and assertsMemoryLiquidafter eviction. Under RAM-only behaviorentry_id1is dropped, sounwrap()panics.src/core/src/cache/tests/policies.rs:26(default_policies) inserts 5 entries into a 2-entry-capacity cache and reads back all 5 — only the last 2 survive now, the earlier reads will returnNoneand the snapshot will diverge.src/core/src/cache/tests/policies.rs:51(insert_wont_fit_cache) inserts an oversized entry and unwraps the read result; under the new code the insert is silently skipped (thereturnhere onvictims.is_empty()), so the read returnsNoneand the test panics. The correspondingliquid_cache__cache__tests__policies__insert_wont_fit_cache.snapis also stale.Please update or replace these tests to verify the new RAM-only behavior (entries are dropped on eviction; oversized entries are not cached) and refresh the affected snapshot.