fix: close S3 credential providers once a newer FileIO supersedes them #7464
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 591 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.382
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #7464"
general
weight: 0.35
sunchao
Which issue does this PR close?
Closes #7390.
Split out of #7363 at a reviewer's request, so the lifecycle change can be reviewed and reverted on its own. #7363 is rebased on this branch.
Rationale for this change
The S3 credential dispatcher keys provider instances by
(FQCN, dispatchKey, catalogProperties)and keeps each one until JVM shutdown. A REST catalog that re-vends credentials gives a table new FileIO properties, so every vended credential registers a new provider. A provider that holds an HTTP client or an auth session, as a refreshing one does, then accumulates for the life of the executor.What changes are included in this PR?
-
ensureInitializedtakes a reference to the instance it returns.- A native
CometS3CredentialBridgeholds that reference and shares it with the bridges it derives (for_path,for_location). The last of them to be dropped gives it back through the newreleaseand its JNI binding.- The last release closes the provider and forgets its key, so a later
ensureInitializedcreates a new instance.FileIOevicts the entries it supersedes. An entry is superseded when it has the same access mode, catalog and table, and different properties, and both carrys3.session-token-expires-at-mswith the new one later. A read identifies the table by its metadata file's directory, since Iceberg writes all of a table's metadata files into one directory (write.metadata.path, or<location>/metadata). A write identifies it by its data location.- Properties that differ without a later expiry on both sides don't say which entry is newer. Two sessions or tenants that share a catalog name can hold different tokens, OAuth credentials or tenant ids for one table. Those entries stay side by side, so they don't evict each other on every task, as in the release.
- A commit that keeps the properties supersedes nothing, so reads of neighboring snapshots share one
FileIO.- The 64-entry LRU bound limits everything else, including providers re-vended without an expiry.
comet-s3-credential-close), so a slowclose()holds up neither the native reader that dropped the last reference nor a new reader for the same key. The shutdown hook and the last release both claim an entry before closing it, so a provider is closed at most once.NativeBase.loadIcebergFileIOForTestingandclearIcebergFileIOCacheForTestingbuild and drop nativeFileIOs, so a CI suite can check provider release over JNI without an S3 server.s3-credential-provider-design.mdands3-credential-providers.mddescribe the reference counts, the expiry rule, and when Comet callsclose().The Parquet path's object store cache never evicts, so its providers still live until shutdown.
How are these changes tested?
Run locally with
-Pspark-4.0on JDK 17:CometS3CredentialDispatcherTest(23 tests) includes the lifecycle tests:- release closes a provider only after its last reference;
- a retired key gets a new provider;
- extra and unknown releases are ignored;
- concurrent acquire and release never use a closed provider;
- release closes on the dispatcher's thread;
- a blocking
close()holds up neither release nor a new reader;- shutdown and a concurrent last release close a provider once.
CometS3CredentialReleaseSuite(no S3 server; runs in CI) builds nativeFileIOs with a test provider. It checks that a later commit whose credentials expire later releases the first provider over JNI, and that clearing the cache releases the rest.iceberg_commonRust tests (27) include cache tests that cover:- eviction on re-vended credentials with a later expiry;
- reads compared by metadata directory, including a custom
write.metadata.path;- writes compared by data location;
- no eviction for a commit with unchanged properties;
- only a later expiry evicting when both entries have one;
- no eviction for properties that differ without a later expiry on both sides (two tenants with different OAuth properties, an expiry on one side only), with the LRU bound still retiring the least recently used entry;
- other tables, catalogs and access modes keep their entries.
CometS3CredentialBridgeSuite(MinIO, manual) addsa table's superseded FileIO releases its CometS3CredentialProvider, which reads one table from two sessions whose catalogs give it different FileIO properties, the second with a later expiry.🤖 Generated with Claude Code