You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "difin (via GitHub)" <gi...@apache.org> on 2025/10/15 00:57:34 UTC

[PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix res… [hive]

difin opened a new pull request, #6131:
URL: https://github.com/apache/hive/pull/6131

   …ource leak from open ResolvingFileIO
   
   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
     2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
     3. Ensure you have added or run the appropriate tests for your PR: 
     4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX:  Your PR title ...'.
     5. Be sure to keep the PR description updated to reflect all changes.
     6. Please write your PR title to summarize what this PR proposes.
     7. If possible, provide a concise example to reproduce the issue for a faster review.
   
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Added try-with-resources for a catalog that is loaded in Catalogs.loadTable().
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   Described in the description of [HIVE-29268](https://issues.apache.org/jira/browse/HIVE-29268).
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducable example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   No
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   Manual check on the local Hive Docker instance.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543


##########
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));
+      }

Review Comment:
   can we avoid logical fallback and close resource when required?
   ````
   private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation,
                                  String catalogName) {
       Optional<Catalog> catalog = loadCatalog(conf, catalogName);
   
       if (catalog.isPresent()) {
           Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
           try {
               return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
           } finally {
               if (catalog.get() instanceof Closeable closeable) {
                 IOUtils.closeQuietly(closeable);
               }
           }
       }
       ....
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on PR #6131:
URL: https://github.com/apache/hive/pull/6131#issuecomment-3634583765

   > > I found that this proposed change resolves the warning for the unclosed `ResolvingFileIO` instance in the logs, but it break the functionality, because it closes `HiveRESTCatalogClient` connection to the `RESTCatalog` server and causes below exceptions when Iceberg tries to commit to an iceberg table.
   > > ```
   > > 2025-10-15 13:29:33 2025-10-15T17:29:33,844 ERROR [HiveServer2-Background-Pool: Thread-159] hive.HiveIcebergStorageHandler: Error while trying to commit job: job_17605493726650_0001, starting rollback changes for table: ice_rest.ice_orc2
   > > 2025-10-15 13:29:33 java.lang.IllegalStateException: Connection pool shut down
   > > 2025-10-15 13:29:33     at org.apache.hc.core5.util.Asserts.check(Asserts.java:38) ~[httpcore5-5.3.1.jar:5.3.1]
   > > 2025-10-15 13:29:33     at org.apache.hc.core5.pool.StrictConnPool.lease(StrictConnPool.java:175) ~[httpcore5-5.3.1.jar:5.3.1]
   > > ...
   > > ```
   > 
   > RESTSessionCatalog -> this.closeables.addCloseable(this.client); @difin, try register it in SessionState: SessionState.get().addCleanupItem(catalog.get())
   
   I checked this, and based on what I found it is not needed because when session gets closed it already closes the rest catalog.
   
   Here is an existing call chain:
   
   `SessionState.close()` --> `Hive.close()` --> `IMetaStoreClient.close()` --> `HiveRESTCatalogClient.close()` --> `restCatalog.close()`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin closed pull request #6131: HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO
URL: https://github.com/apache/hive/pull/6131


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543


##########
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));
+      }

Review Comment:
   can we avoid logical fallback and close resource when required?
   ````
   private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation,
                                  String catalogName) {
       Optional<Catalog> catalog = loadCatalog(conf, catalogName);
   
       if (catalog.isPresent()) {
           Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
           try {
               return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
           } finally {
               if (catalog.get() instanceof AutoCloseable) {
                 IOUtils.closeQuietly((AutoCloseable) resource);
               }
           }
       }
       ....
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543


##########
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));
+      }

Review Comment:
   can we avoid logical fallback and close resource when required?
   ````
   private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation,
                                  String catalogName) {
       Optional<Catalog> catalog = loadCatalog(conf, catalogName);
   
       if (catalog.isPresent()) {
           Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
           try {
               return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
           } finally {
               if (catalog.get() instanceof AutoCloseable closeable) {
                 try {
                   closeable.close();
                 } catch (Exception e) {
                  LOG.warn("An error occurred closing catalog instance, ignoring...", e);
                 }
               }
           }
       }
       ....
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on PR #6131:
URL: https://github.com/apache/hive/pull/6131#issuecomment-3461978653

   
   > I found that this proposed change resolves the warning for the unclosed `ResolvingFileIO` instance in the logs, but it break the functionality, because it closes `HiveRESTCatalogClient` connection to the `RESTCatalog` server and causes below exceptions when Iceberg tries to commit to an iceberg table.
   > 
   > ```
   > 2025-10-15 13:29:33 2025-10-15T17:29:33,844 ERROR [HiveServer2-Background-Pool: Thread-159] hive.HiveIcebergStorageHandler: Error while trying to commit job: job_17605493726650_0001, starting rollback changes for table: ice_rest.ice_orc2
   > 2025-10-15 13:29:33 java.lang.IllegalStateException: Connection pool shut down
   > 2025-10-15 13:29:33     at org.apache.hc.core5.util.Asserts.check(Asserts.java:38) ~[httpcore5-5.3.1.jar:5.3.1]
   > 2025-10-15 13:29:33     at org.apache.hc.core5.pool.StrictConnPool.lease(StrictConnPool.java:175) ~[httpcore5-5.3.1.jar:5.3.1]
   > ...
   > ```
   
   RESTSessionCatalog ->
   this.closeables.addCloseable(this.client);
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin closed pull request #6131: HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO
URL: https://github.com/apache/hive/pull/6131


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6131:
URL: https://github.com/apache/hive/pull/6131#issuecomment-3408363796

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6131) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6131&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6131&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6131&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6131&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6131&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6131)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6131:
URL: https://github.com/apache/hive/pull/6131#issuecomment-3404266195

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6131) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6131&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6131&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6131&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6131&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6131&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6131)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543


##########
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));
+      }

Review Comment:
   can we avoid logical fallback and close resource when required?
   ````
   private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation,
                                  String catalogName) {
       Optional<Catalog> catalog = loadCatalog(conf, catalogName);
   
       if (catalog.isPresent()) {
           Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
           try {
               return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
           } finally {
               if (catalog.get() instanceof AutoCloseable closeable) {
                 IOUtils.closeQuietly(closeable);
               }
           }
       }
       ....
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "okumin (via GitHub)" <gi...@apache.org>.
okumin commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431246618


##########
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));
+      }

Review Comment:
   This file is a copy of [apache/iceberg/mr/.../Catalogs.java](https://github.com/apache/iceberg/blob/main/mr/src/main/java/org/apache/iceberg/mr/Catalogs.java), and the upstream version does not have the equivalent of this change. Why does Apache Iceberg justify the current implementation? Or it is still a problem on upstream, but no MapReduce users are interested in the warning message.
   
   The current implementation is likely to work. For future reference, I'm also curious about what the to-be solution is.



##########
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) {

Review Comment:
   I guess Java 21 provides a smarter way to express this cast.
   https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6131&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543


##########
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));
+      }

Review Comment:
   can we avoid logical fallback and close resource when required?
   ````
   private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation,
                                  String catalogName) {
       Optional<Catalog> catalog = loadCatalog(conf, catalogName);
   
       if (catalog.isPresent()) {
           Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
           try {
               return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
           } finally {
               closeResource(catalog.get());
           }
       }
   
       Preconditions.checkArgument(tableLocation != null, "Table location not set");
       return new HadoopTables(conf).load(tableLocation);
   }
   
   private static void closeResource(Object resource) {
       if (resource instanceof AutoCloseable) {
           try {
               ((AutoCloseable) resource).close();
           } catch (Exception e) {
               throw new RuntimeException("Failed to close resource", e);
           }
       }
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on PR #6131:
URL: https://github.com/apache/hive/pull/6131#issuecomment-3634575705

   > * continuous-integration/jenkins/pr-head
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543


##########
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));
+      }

Review Comment:
   can we avoid logical fallback and close resource when required?
   ````
   private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation,
                                  String catalogName) {
       Optional<Catalog> catalog = loadCatalog(conf, catalogName);
   
       if (catalog.isPresent()) {
           Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
   
           TableIdentifier identifier = TableIdentifier.parse(tableIdentifier);
           try {
               return catalog.get().loadTable(identifier);
           } finally {
               closeResource(catalog.get());
           }
       }
   
       Preconditions.checkArgument(tableLocation != null, "Table location not set");
       return new HadoopTables(conf).load(tableLocation);
   }
   
   private static void closeResource(Object resource) {
       if (resource instanceof AutoCloseable) {
           try {
               ((AutoCloseable) resource).close();
           } catch (Exception e) {
               throw new RuntimeException("Failed to close resource", e);
           }
       }
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543


##########
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));
+      }

Review Comment:
   can we avoid logical fallback and close resource when required?
   ````
   private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation,
                                  String catalogName) {
       Optional<Catalog> catalog = loadCatalog(conf, catalogName);
   
       if (catalog.isPresent()) {
           Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
           try {
               return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
           } finally {
               closeResource(catalog.get());
           }
       }
       ....
   }
   
   private static void closeResource(Object resource) {
       if (resource instanceof AutoCloseable) {
           try {
               ((AutoCloseable) resource).close();
           } catch (Exception e) {
               throw new RuntimeException("Failed to close resource", e);
           }
       }
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6131:
URL: https://github.com/apache/hive/pull/6131#discussion_r2431628543


##########
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));
+      }

Review Comment:
   can we avoid logical fallback and close resource when required?
   ````
   private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation,
                                  String catalogName) {
       Optional<Catalog> catalog = loadCatalog(conf, catalogName);
   
       if (catalog.isPresent()) {
           Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
           try {
               return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
           } finally {
               closeResource(catalog.get());
           }
       }
       ....
   }
   
   private static void closeResource(Object resource) {
       if (resource instanceof Closeable) {
           try {
               ((Closeable) resource).close();
           } catch (Exception e) {
               throw new RuntimeException("Failed to close resource", e);
           }
       }
   }
   ````



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO [hive]

Posted by "difin (via GitHub)" <gi...@apache.org>.
difin commented on PR #6131:
URL: https://github.com/apache/hive/pull/6131#issuecomment-3407731281

   I found that these proposed changes resolve the warning for the unclosed ResolvingFileIO instance in the logs, but it breaks the functionality, because it closes HiveRESTCatalogClient connection to the RESTCatalog server.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org