This is an automated email from the ASF dual-hosted git repository.
diqiu50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new a22daa0680 [#10844] fix(hive): close HiveClientFactory on pool
shutdown (#10854)
a22daa0680 is described below
commit a22daa06802d02234d4892da3e08f5558da4de05
Author: Qi Yu <[email protected]>
AuthorDate: Fri Apr 24 12:12:33 2026 +0800
[#10844] fix(hive): close HiveClientFactory on pool shutdown (#10854)
### What changes were proposed in this pull request?
This PR makes Hive client classloader cleanup deterministic when Hive
client pools are closed.
- Override `HiveClientPool#close()` to call `super.close()` and then
always close `HiveClientFactory` in `finally`.
- Add `TestHiveClientPool` assertion to verify factory-close path is
invoked.
- Add `dev/ci/hive_catalog_oom_repro.sh` stress script to repeatedly
create schema/table, load table, and drop catalog for long-run
metaspace/OOM reproduction.
### Why are the changes needed?
`HiveClientFactory` owns `backendClassLoader` (`HiveClientClassLoader`)
and only closes it in `HiveClientFactory#close()`.
Previously, `HiveClientPool` only closed pooled `HiveClient` instances,
so the factory close path could be skipped, making classloader cleanup
depend on GC timing and causing classloader accumulation under
long-running churn.
Fix: #10844
### Does this PR introduce _any_ user-facing change?
No API changes.
A new internal CI/dev stress script is added for reproduction and
verification.
### How was this patch tested?
- `./gradlew :catalogs:hive-metastore-common:test --tests
org.apache.gravitino.hive.TestHiveClientPool --no-daemon`
- `bash -n dev/ci/hive_catalog_oom_repro.sh`
---------
Co-authored-by: Copilot <[email protected]>
---
.../org/apache/gravitino/hive/HiveClientPool.java | 19 +++++++++++++++++++
.../org/apache/gravitino/hive/TestHiveClientPool.java | 1 +
2 files changed, 20 insertions(+)
diff --git
a/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/HiveClientPool.java
b/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/HiveClientPool.java
index e4d78e58c7..92ca495d61 100644
---
a/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/HiveClientPool.java
+++
b/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/HiveClientPool.java
@@ -18,6 +18,7 @@
*/
package org.apache.gravitino.hive;
+import com.google.common.annotations.VisibleForTesting;
import java.util.Properties;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;
import org.apache.gravitino.hive.client.HiveClient;
@@ -69,6 +70,24 @@ public class HiveClientPool extends
ClientPoolImpl<HiveClient, GravitinoRuntimeE
return false;
}
+ @Override
+ public void close() {
+ if (isClosed()) {
+ return;
+ }
+
+ try {
+ super.close();
+ } finally {
+ closeClientFactory();
+ }
+ }
+
+ @VisibleForTesting
+ void closeClientFactory() {
+ clientFactory.close();
+ }
+
@Override
protected void close(HiveClient client) {
LOG.info("Closing Hive Metastore client");
diff --git
a/catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/TestHiveClientPool.java
b/catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/TestHiveClientPool.java
index 83f397606d..012b4e5a9b 100644
---
a/catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/TestHiveClientPool.java
+++
b/catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/TestHiveClientPool.java
@@ -90,6 +90,7 @@ public class TestHiveClientPool {
clients.close();
assertTrue(clients.isClosed());
Mockito.verify(hiveClient).close();
+ Mockito.verify(clients).closeClientFactory();
}
private HiveClient newClient() {