This is an automated email from the ASF dual-hosted git repository.
jerryshao 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 ebae197414 [#13871] refactor(iceberg): Remove unused close and
resource APIs from the Hive client pool (#13875)
ebae197414 is described below
commit ebae197414c391dd431ce9414e9b7ccac3cd17d2
Author: YangJie <[email protected]>
AuthorDate: Thu Nov 12 07:38:16 2026 -0500
[#13871] refactor(iceberg): Remove unused close and resource APIs from the
Hive client pool (#13875)
### What changes were proposed in this pull request?
- `IcebergHiveCachedClientPool` no longer implements `Closeable`, and
its `close()` is removed.
- `ClosableHiveCatalog` drops the `resources` list, `addResource` and
the loop in `close()` that closed them, plus the `AutoCloseable` branch
in `resetIcebergHiveClientPool`. `closeInternalClientPool` no longer
needs to exclude `IcebergHiveCachedClientPool`.
### Why are the changes needed?
None of this code runs. `HiveCatalog.initialize` always installs
Iceberg's `CachedClientPool` before `resetIcebergHiveClientPool` reads
the old pool, and `ClientPool` is not `AutoCloseable`, so the close
branch is never taken. `closeInternalClientPool` skips
`IcebergHiveCachedClientPool`, and `addResource` has no callers. The
removed `close()` was also unsafe to call: it closed every client in the
JVM-wide cache and shut down the shared scheduler.
Fix: #13871
### Does this PR introduce _any_ user-facing change?
No behavior change. `iceberg-common` is published, so the public methods
`IcebergHiveCachedClientPool.close()`,
`ClosableHiveCatalog.addResource()` and
`ClosableHiveCatalog.getResources()` are gone. Nothing in Gravitino
calls them.
### How was this patch tested?
`TestIcebergHiveCachedClientPool.testCloseMultipleInstances` is removed
with the method it tested. The pool tests added in #14827 closed their
pools with `close()`; they now create the pools without closing them,
and an `@AfterEach` clears the shared cache between tests instead. No
new test: the removed code is unreachable, so there is no behavior to
pin.
---
.../iceberg/common/ClosableHiveCatalog.java | 45 +--------
.../common/utils/IcebergHiveCachedClientPool.java | 11 +--
.../utils/TestIcebergHiveCachedClientPool.java | 105 +++++++++------------
3 files changed, 51 insertions(+), 110 deletions(-)
diff --git
a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ClosableHiveCatalog.java
b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ClosableHiveCatalog.java
index 6b1c98b65d..457080c439 100644
---
a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ClosableHiveCatalog.java
+++
b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ClosableHiveCatalog.java
@@ -20,15 +20,12 @@
package org.apache.gravitino.iceberg.common;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Lists;
import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Field;
import java.security.PrivilegedExceptionAction;
-import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
-import lombok.Getter;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.gravitino.catalog.hadoop.auth.KerberosClient;
import org.apache.gravitino.iceberg.common.authentication.AuthenticationConfig;
@@ -54,18 +51,12 @@ public class ClosableHiveCatalog extends HiveCatalog
implements Closeable, Suppo
private static final Logger LOGGER =
LoggerFactory.getLogger(ClosableHiveCatalog.class);
- @Getter private final List<Closeable> resources = Lists.newArrayList();
-
private KerberosClient kerberosClient;
public ClosableHiveCatalog() {
super();
}
- public void addResource(Closeable resource) {
- resources.add(resource);
- }
-
/**
* Initialize the ClosableHiveCatalog with the given input name and
properties.
*
@@ -99,18 +90,6 @@ public class ClosableHiveCatalog extends HiveCatalog
implements Closeable, Suppo
// First, close the internal HiveCatalog client pool to prevent resource
leaks
closeInternalClientPool();
-
- // Then close any additional resources added via addResource()
- resources.forEach(
- resource -> {
- try {
- if (resource != null) {
- resource.close();
- }
- } catch (Exception e) {
- LOGGER.warn("Failed to close resource: {}", resource, e);
- }
- });
}
@Override
@@ -172,16 +151,6 @@ public class ClosableHiveCatalog extends HiveCatalog
implements Closeable, Suppo
// Then try to close the old pool to release resources
if (oldPool != null) {
- // Try standard close method if available
- if (oldPool instanceof AutoCloseable) {
- try {
- ((AutoCloseable) oldPool).close();
- LOGGER.info("Successfully closed old Hive client pool");
- } catch (Exception e) {
- LOGGER.warn("Failed to close old Hive client pool", e);
- }
- }
-
// Additionally, try to shutdown the internal scheduler thread pool in
Iceberg's
// CachedClientPool to prevent memory leak. This is necessary because
Iceberg's
// CachedClientPool does not implement Closeable and does not properly
clean up
@@ -229,8 +198,7 @@ public class ClosableHiveCatalog extends HiveCatalog
implements Closeable, Suppo
/**
* Close the internal HiveCatalog client pool using reflection. This is
necessary because
- * HiveCatalog doesn't provide a public API to close its client pool. We
need to avoid closing
- * IcebergHiveCachedClientPool twice (once here and once in resources list).
+ * HiveCatalog doesn't provide a public API to close its client pool.
*/
private void closeInternalClientPool() {
try {
@@ -238,13 +206,10 @@ public class ClosableHiveCatalog extends HiveCatalog
implements Closeable, Suppo
clientsField.setAccessible(true);
Object clientPool = clientsField.get(this);
- if (clientPool != null && clientPool instanceof AutoCloseable) {
- // Only close if it's NOT IcebergHiveCachedClientPool
- if (!(clientPool instanceof IcebergHiveCachedClientPool)) {
- ((AutoCloseable) clientPool).close();
- LOGGER.info(
- "Closed HiveCatalog internal client pool: {}",
clientPool.getClass().getSimpleName());
- }
+ if (clientPool instanceof AutoCloseable) {
+ ((AutoCloseable) clientPool).close();
+ LOGGER.info(
+ "Closed HiveCatalog internal client pool: {}",
clientPool.getClass().getSimpleName());
}
} catch (NoSuchFieldException e) {
LOGGER.warn("Could not find 'clients' field in HiveCatalog, skipping
cleanup", e);
diff --git
a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergHiveCachedClientPool.java
b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergHiveCachedClientPool.java
index 982cbb73cc..78f19590c7 100644
---
a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergHiveCachedClientPool.java
+++
b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergHiveCachedClientPool.java
@@ -26,7 +26,6 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import java.io.Closeable;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Comparator;
@@ -84,8 +83,7 @@ import org.slf4j.LoggerFactory;
* active identities or pools created within an expiry interval. By default,
fresh proxy UGIs and
* renewed delegation tokens for the same authentication identity reuse the
same key.
*/
-public class IcebergHiveCachedClientPool
- implements ClientPool<IMetaStoreClient, TException>, Closeable {
+public class IcebergHiveCachedClientPool implements
ClientPool<IMetaStoreClient, TException> {
private static final Logger LOG =
LoggerFactory.getLogger(IcebergHiveCachedClientPool.class);
private static final String CONF_ELEMENT_PREFIX = "conf:";
@@ -283,11 +281,4 @@ public class IcebergHiveCachedClientPool
USER_NAME,
CONF
}
-
- @Override
- public void close() throws IOException {
- clientPoolCache.asMap().forEach((key, value) -> value.close());
- clientPoolCache.invalidateAll();
- if (scheduledExecutorService != null)
scheduledExecutorService.shutdownNow();
- }
}
diff --git
a/iceberg/iceberg-common/src/test/java/org/apache/gravitino/iceberg/common/utils/TestIcebergHiveCachedClientPool.java
b/iceberg/iceberg-common/src/test/java/org/apache/gravitino/iceberg/common/utils/TestIcebergHiveCachedClientPool.java
index 0020700cb8..2615da2256 100644
---
a/iceberg/iceberg-common/src/test/java/org/apache/gravitino/iceberg/common/utils/TestIcebergHiveCachedClientPool.java
+++
b/iceberg/iceberg-common/src/test/java/org/apache/gravitino/iceberg/common/utils/TestIcebergHiveCachedClientPool.java
@@ -32,11 +32,20 @@ import
org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
import org.apache.hadoop.security.token.Token;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.hive.HiveClientPool;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class TestIcebergHiveCachedClientPool {
+ // The cache is static and shared by every pool, so keep the tests
independent of each other.
+ @AfterEach
+ void clearSharedCache() {
+ if (IcebergHiveCachedClientPool.clientPoolCache() != null) {
+ IcebergHiveCachedClientPool.clientPoolCache().invalidateAll();
+ }
+ }
+
@Test
void test() throws IOException {
Configuration configuration = new Configuration();
@@ -112,17 +121,16 @@ public class TestIcebergHiveCachedClientPool {
configuration.set("hive.metastore.uris", "thrift://identity-test:9083");
UserGroupInformation login =
UserGroupInformation.createRemoteUser("catalog");
UserGroupInformation proxy =
UserGroupInformation.createProxyUser("catalog", login);
- try (IcebergHiveCachedClientPool pool =
+ IcebergHiveCachedClientPool pool =
new IcebergHiveCachedClientPool(
- configuration, Map.of(CatalogProperties.CLIENT_POOL_CACHE_KEYS,
"USER_NAME"))) {
- HiveClientPool loginPool = login.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool);
- HiveClientPool proxyPool = proxy.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool);
- Assertions.assertNotSame(loginPool, proxyPool);
- Assertions.assertSame(
- loginPool, login.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool));
- Assertions.assertSame(
- proxyPool, proxy.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool));
- }
+ configuration, Map.of(CatalogProperties.CLIENT_POOL_CACHE_KEYS,
"USER_NAME"));
+ HiveClientPool loginPool = login.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool);
+ HiveClientPool proxyPool = proxy.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool);
+ Assertions.assertNotSame(loginPool, proxyPool);
+ Assertions.assertSame(
+ loginPool, login.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool));
+ Assertions.assertSame(
+ proxyPool, proxy.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool));
}
@Test
@@ -134,17 +142,14 @@ public class TestIcebergHiveCachedClientPool {
kerberos.set("hive.metastore.kerberos.principal",
"hive/[email protected]");
UserGroupInformation first =
UserGroupInformation.createRemoteUser("first");
UserGroupInformation second =
UserGroupInformation.createRemoteUser("second");
- try (IcebergHiveCachedClientPool simplePool =
- new IcebergHiveCachedClientPool(simple, Map.of());
- IcebergHiveCachedClientPool kerberosPool =
- new IcebergHiveCachedClientPool(kerberos, Map.of())) {
- HiveClientPool firstPool =
- first.doAs((PrivilegedAction<HiveClientPool>)
simplePool::clientPool);
- Assertions.assertNotSame(
- firstPool, second.doAs((PrivilegedAction<HiveClientPool>)
simplePool::clientPool));
- Assertions.assertNotSame(
- firstPool, first.doAs((PrivilegedAction<HiveClientPool>)
kerberosPool::clientPool));
- }
+ IcebergHiveCachedClientPool simplePool = new
IcebergHiveCachedClientPool(simple, Map.of());
+ IcebergHiveCachedClientPool kerberosPool = new
IcebergHiveCachedClientPool(kerberos, Map.of());
+ HiveClientPool firstPool =
+ first.doAs((PrivilegedAction<HiveClientPool>) simplePool::clientPool);
+ Assertions.assertNotSame(
+ firstPool, second.doAs((PrivilegedAction<HiveClientPool>)
simplePool::clientPool));
+ Assertions.assertNotSame(
+ firstPool, first.doAs((PrivilegedAction<HiveClientPool>)
kerberosPool::clientPool));
}
@Test
@@ -157,15 +162,13 @@ public class TestIcebergHiveCachedClientPool {
List.of(
Map.<String, String>of(),
Map.of(CatalogProperties.CLIENT_POOL_CACHE_KEYS, "USER_NAME"))) {
- try (IcebergHiveCachedClientPool pool =
- new IcebergHiveCachedClientPool(configuration, properties)) {
- HiveClientPool first =
- proxyWithToken(login, 0).doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool);
- for (int request = 1; request <= 10; request++) {
- UserGroupInformation proxy = proxyWithToken(login, request);
- Assertions.assertSame(
- first, proxy.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool));
- }
+ IcebergHiveCachedClientPool pool = new
IcebergHiveCachedClientPool(configuration, properties);
+ HiveClientPool first =
+ proxyWithToken(login, 0).doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool);
+ for (int request = 1; request <= 10; request++) {
+ UserGroupInformation proxy = proxyWithToken(login, request);
+ Assertions.assertSame(
+ first, proxy.doAs((PrivilegedAction<HiveClientPool>)
pool::clientPool));
}
}
}
@@ -178,17 +181,15 @@ public class TestIcebergHiveCachedClientPool {
UserGroupInformation second =
UserGroupInformation.createRemoteUser("other");
second.setAuthenticationMethod(AuthenticationMethod.KERBEROS);
UserGroupInformation simple =
UserGroupInformation.createRemoteUser("service");
- try (IcebergHiveCachedClientPool pool =
- new IcebergHiveCachedClientPool(configuration, Map.of())) {
- HiveClientPool original =
- UserGroupInformation.createProxyUser("alice", first)
- .doAs((PrivilegedAction<HiveClientPool>) pool::clientPool);
- for (UserGroupInformation real : List.of(second, simple)) {
- Assertions.assertNotSame(
- original,
- UserGroupInformation.createProxyUser("alice", real)
- .doAs((PrivilegedAction<HiveClientPool>) pool::clientPool));
- }
+ IcebergHiveCachedClientPool pool = new
IcebergHiveCachedClientPool(configuration, Map.of());
+ HiveClientPool original =
+ UserGroupInformation.createProxyUser("alice", first)
+ .doAs((PrivilegedAction<HiveClientPool>) pool::clientPool);
+ for (UserGroupInformation real : List.of(second, simple)) {
+ Assertions.assertNotSame(
+ original,
+ UserGroupInformation.createProxyUser("alice", real)
+ .doAs((PrivilegedAction<HiveClientPool>) pool::clientPool));
}
}
@@ -198,25 +199,9 @@ public class TestIcebergHiveCachedClientPool {
first.set("hive.metastore.token.signature", "first");
Configuration second = new Configuration(first);
second.set("hive.metastore.token.signature", "second");
- try (IcebergHiveCachedClientPool firstPool = new
IcebergHiveCachedClientPool(first, Map.of());
- IcebergHiveCachedClientPool secondPool =
- new IcebergHiveCachedClientPool(second, Map.of())) {
- Assertions.assertNotSame(firstPool.clientPool(),
secondPool.clientPool());
- }
- }
-
- @Test
- void testCloseMultipleInstances() throws IOException {
- Configuration configuration = new Configuration();
- Map<String, String> properties = Maps.newHashMap();
- IcebergHiveCachedClientPool pool1 = new
IcebergHiveCachedClientPool(configuration, properties);
- IcebergHiveCachedClientPool pool2 = new
IcebergHiveCachedClientPool(configuration, properties);
-
- Assertions.assertDoesNotThrow(
- () -> {
- pool1.close();
- pool2.close();
- });
+ IcebergHiveCachedClientPool firstPool = new
IcebergHiveCachedClientPool(first, Map.of());
+ IcebergHiveCachedClientPool secondPool = new
IcebergHiveCachedClientPool(second, Map.of());
+ Assertions.assertNotSame(firstPool.clientPool(), secondPool.clientPool());
}
private static UserGroupInformation proxyWithToken(UserGroupInformation
login, int sequence) {