Repository navigation
Refresh reused DataFusion source caches when files are replaced - #12315
lwwmanning wants to merge 9 commits into
Conversation
Store an ObjectGeneration derived from ObjectMeta (size, last_modified, e_tag, and version) alongside each Path-keyed entry in VortexSource and VortexOpener caches (natural_splits, file_schemas, layout_readers, segment_sources, and scan_caches). Cache hits verify the generation under a read lock without allocating, and replacements overwrite the path entry so memory stays bounded to distinct paths. When ObjectMeta lacks a reliable generation token, recompute rather than populating or reading either the per-file caches or DataFusion's FileMetadataCache, and verify e_tag and version alongside DataFusion's CachedFileMetadataEntry::is_valid_for check. Signed-off-by: Will Manning <will@willmanning.io>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
roborev: Combined Review (
|
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
I agree with roborev's first finding, and I think it blocks the merge. PartitionedFile::new(path, size) gives an epoch mtime and no e_tag. So the new reliability check turns off the footer cache and the three shared_* caches for that constructor. The crate's own examples in source.rs and access_plan.rs use it, so each partition of a scan would fetch the footer again. Please keep the path-keyed Weak caches when the metadata is unreliable, and skip only the caches that live longer than one scan.
That change may also fix the clippy failure: shared_layout_reader now has a cognitive complexity of 31, and the limit is 25. The three shared_* helpers are near copies, so one generic helper would remove most of the new branching.
…ersion Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Addressed in
|
…e weak invalidation Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
…placement test Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
…fied Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
Merging this PR will degrade performance by 14.36%Warning vortex-data has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed. 2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
lwwmanning
left a comment
There was a problem hiding this comment.
Review by Gemini 4 Carbon on behalf of @lwwmanning.
Keying the per-file caches on VortexSource and FileMetadataCache by (size, last_modified, e_tag, version) fixes a real stale-read bug on file replacement (and the scalar_subtract_neon walltime blip on CodSpeed is unrelated vortex-array noise). Two issues need to be fixed before merging:
ObjectGeneration::has_reliable_metadatabreaks footer, schema, andnatural_splitscaching forPartitionedFile::newand ETag-less stores:- Requiring a non-empty
e_tagorversioncompletely disablesfile_metadata_cache,file_schemas, andnatural_splitswhenever both areNone. Every programmatic caller usingPartitionedFile::new(path, size)(including our own doc examples and the two existingopener.rsfooter-cache tests this PR had to rewrite fromPartitionedFile::newtoobject_store.head), plus anyObjectStorebackend without ETags, now re-fetches and re-parses the footer on every partition of the same scan and re-walks the layout tree per partition incompute_natural_splits. - Meanwhile,
has_reliable_metadatadoes not even prevent same-size, same-timestamp in-place overwrite collisions on local disk (LocalFileSystemsynthesizese_tagfrom"{inode:x}-{mtime:x}-{size:x}", whereinode == 0on Windows andinodeis unchanged on Unix in-place overwrite). - DataFusion's own
CachedFileMetadataEntry::is_valid_forcontract (used byParquetOpener) caches unconditionally on(size, last_modified). Extending that check withe_tagandversionequality invalidates same-size, same-timestamp replacements whenever a store suppliese_tag/version, without breaking caching when they areNone.
- Requiring a non-empty
- Test suite bloat (
+911/-134):- Removing the
has_reliable_metadata/from_meta_unverifiedsplit makes the 175-linetest_unreliable_generation_recomputes_instead_of_cachingobsolete, andtest_replacement_overwrites_bounded_per_file_cachesinopener.rsduplicatestest_reused_source_byte_partitions_after_object_replacementjust to check.len() == 1.
- Removing the
Remediation Plan
vortex-datafusion/src/persistent/cache.rs:- Simplify
ObjectGenerationto hold(size: u64, last_modified: DateTime<Utc>, e_tag: Option<String>, version: Option<String>)(DateTime<Utc>already implementsEq + Hash), with a single infallibleObjectGeneration::from_meta(meta: &ObjectMeta) -> Selfconstructor andmatches_meta(&self, meta: &ObjectMeta) -> bool. Deletehas_reliable_metadata,from_object_meta, andfrom_meta_unverified. - Simplify
is_cached_metadata_validto:pub(crate) fn is_cached_metadata_valid(entry: &CachedFileMetadataEntry, meta: &ObjectMeta) -> bool { entry.is_valid_for(meta) && entry.meta.e_tag == meta.e_tag && entry.meta.version == meta.version }
- Trim
cache::teststotest_object_generation_distinguishes_all_identity_fieldsandtest_is_cached_metadata_valid(includingNonee_tag/versionmatching when(size, last_modified)match).
- Simplify
vortex-datafusion/src/persistent/format.rs&vortex-datafusion/src/persistent/opener.rs:- Cache unconditionally in
VortexFormat::infer_schema,VortexFormat::infer_stats,VortexOpener::open(file_metadata_cacheandfile_schemas), andnatural_splits_for_fileusingObjectGeneration::from_meta, invalidating whenevermatches_meta/==is false. - Revert the two existing tests in
opener.rsback toPartitionedFile::new(file_path.to_string(), data_size)so they continue verifying thatPartitionedFile::newpopulatesfile_metadata_cache. - Delete
test_unreliable_generation_recomputes_instead_of_cachingand fold theopener.*.len() == 1assertions fromtest_replacement_overwrites_bounded_per_file_cachesintotest_reused_source_byte_partitions_after_object_replacementandtest_reused_source_schema_after_object_replacement.
- Cache unconditionally in
- PR description:
- Remove the claim that files without
e_tagorversion(such asPartitionedFile::new) are no longer cached.
- Remove the claim that files without
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Addressed in
|
robert3005
left a comment
There was a problem hiding this comment.
Generation matching fixes replacements within one store. I found a second identity component missing when a VortexSource is reused across stores.
— Codex (OpenAI)
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
robert3005
left a comment
There was a problem hiding this comment.
I verified the five per-source caches now follow the object-store URL. The normal DataFusion plan also installs a shared footer cache, and that path still has the original collision.
— Codex (OpenAI)
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
lwwmanning
left a comment
There was a problem hiding this comment.
Posted by Claude Opus 5.5 on Will's behalf.
The two new commits fix both of Robert's cross-store findings. The Weak store handle is a sound identity key. It keeps the allocation alive, so a dropped store's address cannot be reused, and upgrade fails once the store is gone. DataFusion's default registry returns the same Arc for each lookup, so planned scans still hit the footer cache.
One test gap remains. Nothing checks that the footer cache still hits for the same store. test_open_populates_file_metadata_cache says the second open hits the cache, but it only checks the rows. If matches_store always returned false, every open would read the footer again and the test would still pass. Please assert that the cached entry after the second open is the same Arc as after the first. A miss puts a new entry, so the assertion would fail.
Signed-off-by: Will Manning <will@spiraldb.com> Co-Authored-By: Will Manning <will@spiraldb.com>
|
Added |
This fixes stale per-file caches in
VortexSourceinvortex-datafusionwhen an object is replaced at the same path. The caches are the natural splits, physical schemas, layout readers, segment sources and scan caches that partitions and executions share. The PR also changes when the opener andVortexFormatreuse footers from the DataFusion file metadata cache.On develop, these per-file caches use the path alone as the key. If a reused source scans a path after the object there was replaced, it can use the old file's row ranges or physical schema. That gives wrong rows, or nulls for columns that the new file added. The footer cache uses the DataFusion check of size and
last_modified, which misses a replacement of the same size within the same timestamp when the store provides ane_tagorversion.With this PR, each cache entry stores an
ObjectGenerationnext to the path:size,last_modified,e_tag, andversion. A lookup uses an entry only when all four fields match, and a new generation overwrites the old entry so each cache still holds one entry per path. The footer cache extends DataFusion'sis_valid_forcheck withe_tagandversionequality while continuing to cache unconditionally (including forPartitionedFile::newand stores withoute_tag/version). The PR also merges the three helpers for the weak-reference caches into one genericshared_weak_entry.Assisted by Antigravity.