← Back to Pull requests

fix: close S3 credential providers once a newer FileIO supersedes them #7464

Closed
unknown closed this pull request without merging on Nov 20, 2026 03:07 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 20:27 UTC
Author

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?

  • The dispatcher counts references.

  • - ensureInitialized takes a reference to the instance it returns.
    - A native CometS3CredentialBridge holds 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 new release and its JNI binding.
    - The last release closes the provider and forgets its key, so a later ensureInitialized creates a new instance.
  • The FileIO cache retires superseded entries. Inserting a table's new FileIO evicts the entries it supersedes. An entry is superseded when it has the same access mode, catalog and table, and different properties, and both carry s3.session-token-expires-at-ms with 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.
  • The dispatcher closes released providers on its own daemon thread (comet-s3-credential-close), so a slow close() 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.

  • Test hooks. NativeBase.loadIcebergFileIOForTesting and clearIcebergFileIOCacheForTesting build and drop native FileIOs, so a CI suite can check provider release over JNI without an S3 server.

  • Docs. s3-credential-provider-design.md and s3-credential-providers.md describe the reference counts, the expiry rule, and when Comet calls close().
  • 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.0 on 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 native FileIOs 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.

  • The iceberg_common Rust 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) adds a 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

    Diff: 591 lines (+443 / -148) across 7 files Reviewer: sunchao Review duration: 23440m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.0% (MEDIUM) · Higher = larger blast radius
    50.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.7% · Safe to merge
    19.7%