Snowflake: Avoid unbounded FileIO accumulation in SnowflakeCatalog
Apache Iceberg version main @ 3038fde68
Query engine N/A (catalog-level, engine-agnostic)
Please describe the bug
SnowflakeCatalog.newTableOps(TableIdentifier) creates a new FileIO on every table load and unconditionally registers it with closeableGroup (snowflake/src/main/java/org/apache/iceberg/snowflake/SnowflakeCatalog.java line 255-256, before this fix). CloseableGroup backs its closeable list with a Deque that only grows until the whole group is closed, so a long-lived SnowflakeCatalog instance that repeatedly loads or refreshes tables (a REST catalog server, a long-running Spark session) accumulates one FileIO per load, holding native resources (S3/Azure/GCS clients, connection pools) until the catalog itself is closed.
GlueCatalog.newTableOps(TableIdentifier) (aws/src/main/java/org/apache/iceberg/aws/glue/GlueCatalog.java) has the same "new FileIO per table load" design but already solves this with core's FileIOTracker (core/src/main/java/org/apache/iceberg/io/FileIOTracker.java), which tracks each FileIO against its TableOperations with a weak-keyed cache and closes it once the TableOperations is no longer reachable.
Steps to reproduce
- Create one
SnowflakeCataloginstance. - Call
loadTable()(ornewTableOps()) repeatedly, including reloading the same table. - Expected: unreferenced
FileIOinstances get reclaimed independently of catalog lifetime, matchingGlueCatalog. Actual: every call adds aFileIOtocloseableGroupthat is never released untilcatalog.close().
Additional context N/A, covered above.
#17096 by @thswlsqls was moved to draft in July, closed by the stale bot in August without a review, and its branch was deleted in September. @thswlsqls, if you'd like to continue it, I'll step aside; otherwise I'd like to pick this up and credit your work. The plan is to track each table's FileIO with core's FileIOTracker, as GlueCatalog does, so it is closed once its TableOperations is unreachable instead of being held until the catalog closes.