Repository navigation
fix(cache): serve cached entries only to the file they came from - #526
Merged
anoop-narang merged 1 commit intoOct 16, 2026
Merged
Conversation
A cache key keeps 16 bits of the file id, while file ids come from a
counter that only climbs. The 65,537th distinct file a process registers
therefore computes the same keys as the first, and reads the first
file's cached data: silently wrong rows when the column types match, a
panic in `RecordBatch::try_new` when they do not. The narrowing is
guarded by `debug_assert!` only, so release builds carry on.
Record the full file id ("identity") with every cached entry, in the
index and as an 8-byte trailer on every object written to disk, and
compare it on every lookup. A mismatch reads as a miss, so the caller
falls back to parquet and gets correct data. An insert replaces whatever
held the key, so the newer file can still cache its own data.
The trailer is what makes the disk side safe without changing how
objects are keyed: an eviction or flush that lands after the key changed
hands leaves bytes that name the old identity, and the new owner's read
of them misses. It follows the payload so the payload keeps its
alignment, and the disk budget is charged for it.
`LiquidCache::insert`, `get`, `eval_predicate`, `prefetch`,
`try_read_liquid`, `contains`, `read_entry` and `eval_predicate_on_entry`
take the identity as a new argument. Callers whose keys are already
unique can pass any constant.
The `should_panic` test for an oversized file id pinned the debug-only
guard; it is replaced by one pinning the narrowing the identity check
relies on.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #526 +/- ##
=======================================
Coverage ? 81.38%
=======================================
Files ? 80
Lines ? 13666
Branches ? 13666
=======================================
Hits ? 11122
Misses ? 2216
Partials ? 328 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@XiangpengHao I am merging this as a fix as current main is giving wrong results on long running processes. Let me know your thoughts on this. There is more to be done to make liquidcache better for long running processes. |
Collaborator
|
LGTM thank you @anoop-narang |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
After a process has read 65,536 distinct parquet files, the next file is served the first file's cached data.
Why
A cache key keeps only 16 bits of the file id, but file ids come from a counter that only climbs (
register_or_get_file). File 65,537 gets id 65536, which narrows to 0, so its keys are the first file's keys. Its reads then return the first file's arrays: wrong rows if the column types match, a panic inRecordBatch::try_newif they don't. The only guard is adebug_assert!, so release builds hit this silently.Repro
files_whose_keys_collide_do_not_share_entriescaches a batch for one file, registers 65,535 more, and reads the same batch through the 65,537th. Onmainit fails in release with "a file was served another file's cached data" (in debug, at thedebug_assert!).Fix
Keep the full file id with every cached entry and check it on every read. A mismatch is a cache miss, so the reader falls back to parquet. A write replaces whatever held the key.
The key stays 64 bits because
congeesupports only 8-byte keys.API change
insert,get,eval_predicate,prefetch,try_read_liquid,contains,read_entryandeval_predicate_on_entryonLiquidCachetake anidentity: u64. Callers with unique keys can pass any constant (the README and examples pass0).Cost: 8 bytes per entry and per disk object, plus one comparison per read.
Tests
test_cache_entry_id_new_panic_file_idrequired thedebug_assert!panic. It is replaced by a test that file ids keep their low 16 bits.Follow-ups