perf: cache Iceberg FileIO per executor instead of building one per task - #6106
Conversation
Every native Iceberg scan or write task built its own FileIO, and since iceberg-rust creates the storage client lazily per instance, every task also opened and tore down its own client: an S3 client, or with hdfs-native a NameNode session. Spark's Hadoop layer shares one client per executor JVM. load_file_io now serves clones from a per-executor cache and only builds on a miss. The key is everything that shapes the client: access mode, catalog name, the full reference path, and the whole catalog property bag. The path is in the key because the S3 access bridge is constructed with the bucket and path of the reference location, so a bridge built for one table must not serve another. memory:/// is never cached, the map clears past 64 entries, and release_runtime clears it with the runtime. Closes apache#6105 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Review of apache#6106 found that the bound cleared the whole cache, including the entry a running query was using, and dropped every FileIO while holding the lock, where the last clone of an S3 access bridge releases JNI global refs. The cache is now a small LRU that evicts one entry per insert, and evicted or replaced FileIOs are dropped after the lock is released. The builder is injected into cached_file_io so tests can count builds: a repeated identical load builds once, a load without a key builds every time, memory:/// never enters the cache, and eviction removes the least recently used entry. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Review of the first revision found three problems, all addressed in the latest push:
|
…lise A read whose configured S3 access provider fails to initialise falls back to opendal's default chain. Caching that FileIO made the fallback sticky for every later task on the executor. storage_factory_for and build_file_io now report whether the build is cacheable, and a degraded build is returned without being inserted so the next task retries. Also splits the S3 operator cache follow-up into apache#6109 and updates two comments that still described per-task lifetimes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Second review round, three findings, all addressed in the latest push:
|
andygrove
left a comment
There was a problem hiding this comment.
Thanks for the careful per-backend breakdown in the description. It makes the scope of this change much easier to reason about.
HDFS support (#5898) isn't on main yet, so today the gain comes only from the S3 factory and bridge construction. CometS3CredentialDispatcher.ensureInitialized already caches the provider JVM-side via KEY_TO_HANDLE.computeIfAbsent, so the per-task bridge cost is two new_string calls, two global refs and a map lookup. The provider isn't re-initialised. Do you have measurements showing the per-task FileIO build cost matters for S3 on its own? If not, would it make sense to land this together with #5898 or #6109, where the cache is clearly needed?
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
There was a problem hiding this comment.
The key carries the whole catalog property bag, which can include vended s3.access-key-id, s3.secret-access-key and s3.session-token. Could we drop Debug here, or implement a redacting one, so a future {:?} can't leak credentials into logs?
There was a problem hiding this comment.
Replaced the derive with a manual Debug that prints access_mode, catalog_name and reference_path and omits properties. cache_key_debug_does_not_leak_properties asserts the exact output from a key built with vended secrets.
sunchao
left a comment
There was a problem hiding this comment.
Summary
- Prior state and problem: Each native Iceberg task rebuilt its
FileIO, storage configuration, and optional JNI credential bridge. - Design approach: Add a bounded, 64-entry executor cache keyed by access mode, catalog, full reference path, and all catalog properties.
- Correctness / compatibility analysis: No introduced P1/P2 issues found within this review. Checked configuration isolation, credential refresh behavior, ownership, and cleanup against the pinned Iceberg implementation and Spark 3.4.3, 3.5.9, 4.0.4, 4.1.3, and 4.2.0 sources.
- Key design decisions: Exclude
memorystorage and degraded credential-provider builds. Drop evicted values outside the mutex. The implementation stays local to the shared Iceberg helper. - Implementation sketch:
load_file_iochecks the cache, callsbuild_file_ioon misses, and returns clones sharing storage.release_runtimedrains the cache. - Behavioral changes worth calling out: S3 factory/configuration/bridge reuse does not reuse its per-file operator or signer. Cache lookup adds property copying, sorting, hashing, and locking. End-to-end performance was not measured.
- Suggested improvements: None meeting the requested P1/P2 threshold.
Reviewed full SHA 36ffdc1f57043043b0e6cc16e7b33096693a97b8 against base 9a4d5f28368d4fbb54ac23c14c5d52d5637ce26d, covering all three commits and the complete four-file PR diff using their merge base. The PR remains non-draft.
Routed skills: review-comet-pr and review-comet-ffi-pr. Read existing human reviews, issue comments, inline comments, and threads. No existing P1/P2 blocker was substantiated: closeAll() already documents test/shutdown-only use, HDFS is unsupported at this pin, and no cache-key logging was found.
Exact-head CI: Comet CI and CodeQL report action_required, with no jobs executed. Only labeling passed.
Validation: All 78 native Iceberg tests passed with --no-default-features. Five disposable cache-lifecycle/concurrency tests also passed using the exact cache implementation with Arc probes. JVM/MinIO, Spark SQL, upstream Iceberg suites, and default-feature builds were not validated here. No project code or GitHub state was changed.
andygrove
left a comment
There was a problem hiding this comment.
sunchao's right that closeAll() only runs from tests and the shutdown hook, so I'm fine with cached bridges keeping their handle. I'll take the Kerberos question to #5898, since HDFS only arrives there. The Debug derive on FileIoCacheKey still worries me, though. The key holds the whole catalog property bag, including vended s3.secret-access-key and s3.session-token, so one {:?} in a future log line leaks them. Could it get a Debug impl that prints only the catalog name, access mode and reference path? The tests' assert_ne! calls need Debug, which is why dropping the derive outright would mean rewriting them.
The key carries the whole catalog property bag, including vended S3 secrets, so the derived Debug could leak them through any future log line. A manual impl prints only access mode, catalog name and reference path; the test asserts the exact output from a key built with secrets. The bridge struct doc no longer describes a per-scan lifetime. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Latest push replaces the derived On measurements: none yet, and I would rather not invent one. |
andygrove
left a comment
There was a problem hiding this comment.
Thanks for the Debug fix. That's exactly what I was after. And thanks for the answer on measurements. #6109's operator cache can't outlive a task without this, and #5898 is blocked upstream, so I'm happy for this to land on its own.
Two things before it goes in.
Could this PR also update docs/source/contributor-guide/s3-credential-provider-design.md? Line 109 says the storage-prefix filter is applied in iceberg_scan.rs::load_file_io, and it now lives in iceberg_common.rs::build_file_io. It would also help to add a short paragraph there about the new executor FileIO cache, since that page is where bridge lifetimes are explained for the Parquet path. The things worth capturing are what the key holds and why the reference path has to be in it, that memory:/// and degraded read builds are never cached, and that a bridge and its dispatcher handle now live as long as their cache entry. The path matters most. Dropping it from the key looks like a free hit-rate win, and it would hand one table's bridge to another.
Thanks for running IcebergReadFromS3Suite. That suite covers vended static credentials without a provider, though. The case where this cache saves real work today is a custom CometS3CredentialProvider on the Iceberg path, and the suite that drives it is CometS3CredentialBridgeSuite, including the two-catalog isolation test. It's a manual suite, so CI won't run it. Could you run it against this branch and add the result to the testing section?
The property filter now lives in iceberg_common.rs::build_file_io. The new section records what the cache key holds and why the reference path stays in it, that memory:/// and degraded read builds are never cached, and that a bridge and its dispatcher handle live as long as their entry. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Docs updated: the filter reference now points at
|
Which issue does this PR close?
Closes #6105.
Rationale for this change
Every native Iceberg scan or write task builds its own
FileIO. On a production workload that was 40,317FileIOconstructions against one endpoint for a single query, each one rebuilding the storage factory, its parsed configuration and, for S3 with a custom access provider, the JNI bridge. Spark's Hadoop layer shares one client per executor JVM. Details in #6105.What changes are included in this PR?
load_file_ioiniceberg_common.rsnow serves clones of a per-executor LRU cache and builds only on a miss; the previous body becomesbuild_file_io. Clones share iceberg-rust'sArc<OnceLock<Arc<dyn Storage>>>, so all tasks on an executor share oneStorage.The key is everything that shapes the client: access mode, catalog name, the full reference path, and the whole catalog property bag. The path is included because the S3 access bridge is constructed with the bucket and
url.path()of the reference location and the JVM provider is called with exactly that pair, so a bridge built for one table must not serve another.memory:///is never cached; the write path assembles manifest bytes there per task. The cache holds 64 entries and evicts the least recently used one, dropping it after the lock is released since the last clone of aFileIOreleases JNI global refs.release_runtimedrains it with the Tokio runtime. A read whose configured S3 access provider failed to initialise falls back to opendal's default chain, as before; that build is returned but not cached, so the next task retries the provider instead of inheriting the fallback.docs/source/contributor-guide/s3-credential-provider-design.mdpoints the property filter atbuild_file_ioand gains a section on the executorFileIOcache: what the key holds and why the reference path stays in it, what is never cached, and how long a bridge and its handle live.What is actually shared, per backend
Sharing a
FileIOshares what itsStorageholds. At the pinned iceberg-rust rev that differs by backend:Storageholdss3,s3a, aliases,gs,osscreate_operatorbuilds a new opendalOperatorper file openensureInitialized. Not the client or signer: opendal builds a newSignerper operator, and HTTP pooling is already process-widehdfs(#5898)memoryfileSo for S3-family backends this PR is necessary but not sufficient for client reuse: an operator cache inside
OpenDalStorage::S3, mirroring what the HDFS backend already does, would make the sharedStoragealso share the signer and its access cache. That is an iceberg-rust change, tracked in #6109. Without an executor-levelFileIOcache such an operator cache would die with every task, which is why this lands first.How are these changes tested?
iceberg_common.rs: the key separates access mode, path, catalog and properties and isNoneformemory:///;cached_file_iobuilds once for repeated identical loads and every time without a key;load_file_io("memory:///")leaves the cache untouched; a degraded build is returned but never cached; eviction removes the least recently used entry and a re-insert replaces without evicting.cargo clippy --all-targets -p datafusion-comet -- -D warningsis clean.CometIcebergNativeSuite,CometIcebergWriteActionSuiteand the MinIO-backedIcebergReadFromS3Suite, which runs REST catalog vending with wrong access immediately before correct access against the same bucket and catalog.CometS3CredentialBridgeSuite(MinIO, listed indev/ci/check-suites.py), which drives a customCometS3CredentialProvideron both the Parquet and Iceberg paths: 6 tests pass on the merged head, including the two-catalog isolation test and the location-scoped tests from fix: refresh S3 policy locations when a location's credential fails #6223.AI Disclosure
Drafted, implemented and tested with AI assistance (Claude Code); reviewed before submission.
🤖 Generated with Claude Code