Skip to content

fix: key the Parquet metadata cache by object store - #7856

Open
sshpuntoff wants to merge 2 commits into
apache:mainfrom
Qualytics:metadata-cache-by-store
Open

sshpuntoff wants to merge 2 commits into
apache:mainfrom
Qualytics:metadata-cache-by-store

Conversation

@sshpuntoff

@sshpuntoff sshpuntoff commented Dec 4, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Closes #7855.

Rationale for this change

Two scans in one native plan share a cached Parquet footer when their files have the same path and size in different object stores. The second scan then prunes with the first file's statistics and silently drops rows. The issue has an example.

The root cause is apache/datafusion#27579: the cache key is the path inside the store, without the store.

What changes are included in this PR?

  • store_metadata_cache(runtime_env, object_store_url) returns a view of the shared FileMetadataCache that puts the object store URL in every key.
  • The Parquet scan and the deletion-vector prefetch of a Delta scan use this view instead of the shared cache.
  • The memory limit and eviction are unchanged, because the entries still live in the one shared cache.

This can be removed once Comet moves to a DataFusion release whose cache key tells apart every store Comet registers. The key proposed in apache/datafusion#27580 drops the URL's userinfo, so two ABFS containers of one account would still share an entry. The ABFS scan test below covers that case through the upgrade.

How are these changes tested?

  • same_path_and_size_in_two_stores_do_not_share_cached_metadata: two in-memory stores, same path, same size, different contents, with a filter, scanned as A, B, then A again in one session. Without the fix the B scan returns 0 rows from 1 cache hit and 0 footer reads. The second A scan must reuse the footer the first one cached.
  • same_path_and_size_in_two_abfs_containers_do_not_share_cached_metadata: the same case for two ABFS containers of one account, registered through CometObjectStoreRegistry.
  • stores_do_not_share_the_entry_of_a_path: unit test of the view.
  • cargo test -p datafusion-comet --lib passes.

🤖 Generated with Claude Code

One runtime serves every scan of a native plan, and its Parquet metadata
cache is keyed by a file's path within its store. An entry is valid while
the file's size and modification time are unchanged, and every file a scan
lists carries the same modification time. Two scans of one plan that read
files of the same path and size from different stores therefore shared an
entry: the second file was read with the first one's footer, whose
statistics could prune its rows.

Read and write the cache through a view that puts the store's URL in the
key. The scan and the deletion-vector prefetch of a Delta scan use the
same view, so the prefetch still serves the scan.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@sunchao sunchao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scan and Delta deletion-vector prefetch use the same registered data-store URL, so they can share a footer while keeping one eviction budget. I found no blocking correctness issue in this implementation.

Since this can silently drop rows, I’d suggest a backport to 1.2. 1.1 and 1.0 also use the shared cache keyed by path if we want to cover those lines.

Comment thread native/core/src/parquet/parquet_exec.rs Outdated

let location = "data/part-0.parquet";
let url_a = ObjectStoreUrl::parse("s3://bucket-a").unwrap();
let url_b = ObjectStoreUrl::parse("s3://bucket-b").unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also run this case with two ABFS containers on the same account, using CometObjectStoreRegistry as in the existing registration test? This implementation correctly keeps the container in a@account versus b@account. The proposed DataFusion key currently strips the username, which would make those keys identical given the same options and path. I’d qualify the removal note in the PR description and keep this scan test through the upgrade.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added same_path_and_size_in_two_abfs_containers_do_not_share_cached_metadata in c32a696. It registers two containers of one account through CometObjectStoreRegistry and prepare_object_store_with_configs, backed by in-memory stores, and runs the same A, B, A scans. I qualified the removal note in the description to say the proposed DataFusion key would not separate them.

Comment thread native/core/src/parquet/parquet_exec.rs Outdated
// Store A first, then store B, in one runtime.
let shared = new_session().await;
let (rows_a, _) = scan_rows(Arc::clone(&shared), url_a.clone()).await;
let (rows_b, scan_b) = scan_rows(Arc::clone(&shared), url_b.clone()).await;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the third scan to read A again after B in the shared session, in place of the separate B-alone run? The current row and I/O assertions also pass if each scan gets a fresh cache. Expecting zero rows, one cache hit and zero footer reads on the second A scan would show that B left A’s entry intact and a new reader can still reuse it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c32a696. The test now scans A, B, then A again in one session and expects (0 rows, 1 cache hit, 0 footer reads) from the second A scan. The separate B-alone run is gone.

impl StoreMetadataCache {
fn key(&self, location: &Path) -> Path {
Path::from_iter(
std::iter::once(PathPart::from(self.store.as_str())).chain(location.parts()),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we encode the store URL once when constructing the view and keep it as a single-segment Path? PathPart::from percent-encodes the same URL on every lookup, again on insertion after a miss, and once per entry in list_entries. With a stored prefix, key can clone it and call extend(location), and location can use key.prefix_match(&self.prefix).map(Path::from_iter).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c32a696. The view keeps the encoded URL as a one-segment Path; key clones and extends it, and location uses prefix_match.

…ntainers

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet footer cache returns another file's footer when two stores share a path

2 participants