LuciferYang commented on code in PR #13450:
URL: https://github.com/apache/gravitino/pull/13450#discussion_r4081639753


##########
core/src/main/java/org/apache/gravitino/stats/storage/JdbcPartitionStatisticStorage.java:
##########
@@ -356,8 +356,18 @@ public void updateStatistics(
 
   @Override
   public void close() throws IOException {
-    // DataSource lifecycle is managed externally by the factory
     LOG.debug("Closing JdbcPartitionStatisticStorage");
+    // This storage is the only reachable owner of the pooled DataSource: the
+    // factory that created it is discarded by the manager, so close must
+    // release the pool. DataSources that do not implement AutoCloseable keep
+    // their externally-managed lifecycle.
+    if (dataSource instanceof AutoCloseable) {
+      try {
+        ((AutoCloseable) dataSource).close();
+      } catch (Exception e) {
+        throw new IOException("Failed to close JDBC DataSource", e);
+      }
+    }

Review Comment:
   Done. `close()` now guards with an `AtomicBoolean` (`compareAndSet(false, 
true)`), so a second call returns immediately and the underlying `close()` runs 
at most once.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to