Skip to content

[filesystem] Respect file-io.allow-cache and close evicted REST FileIO instances - #11538

Draft
ZENOTME wants to merge 5 commits into
apache:masterfrom
ZENOTME:codex/s3-client-lifecycle
Draft

ZENOTME wants to merge 5 commits into
apache:masterfrom
ZENOTME:codex/s3-client-lifecycle

Conversation

@ZENOTME

@ZENOTME ZENOTME commented Nov 30, 2026 •

Copy link
Copy Markdown

Purpose

Linked issue: fixes #11532 (related to #8548).

When RESTTokenFileIO rotates temporary credentials (e.g., S3 STS session tokens), it already manages a bounded FILE_IO_CACHE with file-io.allow-cache=false and closes evicted FileIO instances. However, underlying object-store clients (such as S3A clients and their AWS SDK timer threads sdk-ScheduledExecutor) still leaked on every token rotation because:

  1. S3FileIO (as well as COSNFileIO, GSFileIO, and AzureFileIO) ignored file-io.allow-cache=false, always inserted every credential-bearing configuration into an unbounded static CACHE, and did not override FileIO.close(). OBSFileIO read file-io.allow-cache but lacked close(), while OSSFileIO and JindoFileIO could NPE in close() if fsMap had not been initialized yet.
  2. PluginFileIO (used by S3Loader / S3ALoader / OSSLoader, etc.) and ResolvingFileIO did not override FileIO.close(), so RESTTokenFileIO's cache eviction callback never reached the underlying plugin FileIO.
  3. FileIO.checkAccess() instantiated and probed a FileIO via exists(path) on preferIO / fallbackIO / HadoopFileIOLoader paths and then discarded it without closing before FileIO.get() created a second instance, leaking an uncached client per load.
  4. RESTTokenFileIO.FILE_IO_CACHE used a fixed 10-hour expireAfterAccess regardless of token expiration, keeping expired short-lived tokens cached for up to 10 hours while prematurely evicting longer-lived tokens (e.g., 24h) after 10 hours.

Changes

  • Concurrent first access to the same filesystem key now shares one initialization per FileIO instance. Different buckets can initialize concurrently, and closing an owner during initialization still cleans up its unpublished private client.

  • S3FileIO:

    • Honor file-io.allow-cache=false by bypassing static S3FileIO.CACHE and managing per-instance S3AFileSystem instances in fsMap (preserving Apache HTTP pool-shutdown recovery).
    • Track retired uncached RecoverableS3AFileSystem instances removed during pool-shutdown recovery and close both active and retired instances in synchronized close() (null-safe when fsMap == null).
    • Keep existing static S3FileIO.CACHE behavior completely unchanged when file-io.allow-cache=true.
  • Other object-store FileIO plugins (OSS, OBS, COSN, GS, Azure, Jindo):

    • Honor file-io.allow-cache=false in COSNFileIO, GSFileIO, and AzureFileIO by bypassing their static CACHE.
    • Add null-safe synchronized close() in OBSFileIO, COSNFileIO, GSFileIO, and AzureFileIO, and add the missing fsMap != null guard in OSSFileIO.close() and JindoFileIO.close().
  • FileIO, PluginFileIO, & ResolvingFileIO:

    • Reuse the successfully probed FileIO instance in FileIO.get() (probeAccess(...)) and close it on probe failure or missing requiredOptions.
    • Implement synchronized close() in PluginFileIO and ResolvingFileIO forwarding to the underlying delegate FileIO(s) under the plugin/resolving context classloader.
  • RESTTokenFileIO.FILE_IO_CACHE:

    • Replace fixed 10h expireAfterAccess with a Caffeine Expiry based on token.expireAtMillis + 5m_grace (Long.MAX_VALUE tokens do not expire by time and remain bounded by maximumSize), while preserving the existing immediate IOUtils.closeQuietly(value) eviction listener.

Note: This PR focuses on closing the file-io.allow-cache=false lifecycle and eviction cleanup path across object-store FileIO plugins. Reusing a single S3Client across credential rotations via dynamic credentials refresh will be submitted in a separate follow-up PR built on top of this change.

Tests

  • Added concurrent first-access coverage for the resolver, private S3A instances and shared GCS filesystems. With four simultaneous reads against a local S3 endpoint, the SDK sent one bucket probe and its scheduler thread count returned to zero after close. Two concurrent COSN readers and a subsequent FileIO all received the same live filesystem.

  • FileIOTest: verifies preferIO reuses the probed instance (1 created, 1 closed) and closes failed probes before falling back.

  • PluginFileIOTest: verifies close() forwards to the loaded delegate under pluginClassLoader() and is idempotent.

  • ResolvingFileIOTest: verifies close() closes all resolved delegates once.

  • RESTTokenFileIOTest: verifies finite-TTL tokens (including 24h TTL) expire at expireAtMillis + grace without premature 10h eviction, Long.MAX_VALUE tokens do not expire by time, and maximumSize evictions close immediately.

  • S3FileIOLifecycleTest: verifies file-io.allow-cache=false bypasses static S3FileIO.CACHE, closes uncached S3AFileSystem instances on close() (including before first use and retired instances after pool-shutdown recovery), and verifies file-io.allow-cache=true keeps existing shared-cache semantics.

  • Verified checkstyle, spotless, enforcer, and compilation across paimon-common and all 7 object-store modules (s3-impl, oss-impl, obs-impl, cosn-impl, gs-impl, azure-impl, jindo), plus targeted unit tests in paimon-common, paimon-s3-impl, paimon-oss-impl, and paimon-gs-impl.

@ZENOTME
ZENOTME marked this pull request as draft November 30, 2026 06:30
@ZENOTME
ZENOTME force-pushed the codex/s3-client-lifecycle branch from 8e824cf to 80208c1 Compare November 30, 2026 08:48
@ZENOTME ZENOTME changed the title [s3] Reuse S3 clients across REST credential refreshes [s3] Respect file-io.allow-cache and close evicted REST FileIO instances Nov 30, 2026
@ZENOTME
ZENOTME marked this pull request as ready for review November 30, 2026 08:51
@ZENOTME
ZENOTME force-pushed the codex/s3-client-lifecycle branch 2 times, most recently from 32bf308 to 1b759c5 Compare November 30, 2026 09:00
@ZENOTME

ZENOTME commented Nov 30, 2026

Copy link
Copy Markdown
Author

cc @JingsongLi

@ZENOTME
ZENOTME force-pushed the codex/s3-client-lifecycle branch from 1b759c5 to 6a3b0dd Compare November 30, 2026 09:23
@ZENOTME ZENOTME changed the title [s3] Respect file-io.allow-cache and close evicted REST FileIO instances [filesystem] Respect file-io.allow-cache and close evicted REST FileIO instances Nov 30, 2026
@ZENOTME
ZENOTME force-pushed the codex/s3-client-lifecycle branch from 6a3b0dd to 2ad88e7 Compare November 30, 2026 09:53
ZENOTME and others added 2 commits November 30, 2026 18:04
…ject-store FileIOs

Co-authored-by: Cursor <cursoragent@cursor.com>
@ZENOTME
ZENOTME force-pushed the codex/s3-client-lifecycle branch from 2ad88e7 to f61a71d Compare November 30, 2026 10:06
ZENOTME and others added 2 commits November 30, 2026 19:26
…o cache map

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep closed checks and map publish under the instance monitor, but run
FileIO.get/createFileSystem outside so different authorities can initialize
in parallel. Close unpublished creations when racing with close. Mark Jindo
closed before closing the presigner and always clear both FS maps in finally.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ZENOTME
ZENOTME marked this pull request as draft November 30, 2026 11:46
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.

[Bug] S3FileIO retains S3A clients and SDK threads across session credential rotations

1 participant