From e57209aba2b5c896639de4957603080b8097a800 Mon Sep 17 00:00:00 2001 From: Dmitriy Fingerman Date: Tue, 14 Oct 2025 20:54:53 -0400 Subject: [PATCH 1/2] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO --- .../main/java/org/apache/iceberg/mr/Catalogs.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java index e431e0323a45..ff5d7f513f1d 100644 --- a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java +++ b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java @@ -111,7 +111,17 @@ private static Table loadTable(Configuration conf, String tableIdentifier, Strin if (catalog.isPresent()) { Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set"); - return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier)); + + if (catalog.get() instanceof AutoCloseable) { + try (AutoCloseable ignored = (AutoCloseable) catalog.get()) { + return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier)); + } catch (Exception e) { + throw new RuntimeException("Failed to close catalog", e); + } + } else { + // fallback if not AutoCloseable + return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier)); + } } Preconditions.checkArgument(tableLocation != null, "Table location not set"); From d6b7b35dd9c9015eabd11dbdf44c546b8406bbad Mon Sep 17 00:00:00 2001 From: Dmitriy Fingerman Date: Wed, 15 Oct 2025 11:06:06 -0400 Subject: [PATCH 2/2] code review Oct 15. --- .../java/org/apache/iceberg/mr/Catalogs.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java index ff5d7f513f1d..c1ff42b0ab5e 100644 --- a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java +++ b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java @@ -19,10 +19,12 @@ package org.apache.iceberg.mr; +import java.io.Closeable; import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.Set; +import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.iceberg.CatalogUtil; import org.apache.iceberg.PartitionSpec; @@ -111,16 +113,12 @@ private static Table loadTable(Configuration conf, String tableIdentifier, Strin if (catalog.isPresent()) { Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set"); - - if (catalog.get() instanceof AutoCloseable) { - try (AutoCloseable ignored = (AutoCloseable) catalog.get()) { - return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier)); - } catch (Exception e) { - throw new RuntimeException("Failed to close catalog", e); - } - } else { - // fallback if not AutoCloseable + try { return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier)); + } finally { + if (catalog.get() instanceof Closeable closeable) { + IOUtils.closeQuietly(closeable); + } } }