diff --git a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/pool/CachedClientPool.java b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/pool/CachedClientPool.java index c719d582c0b0..1c2080149c17 100644 --- a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/pool/CachedClientPool.java +++ b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/pool/CachedClientPool.java @@ -84,7 +84,14 @@ public CachedClientPool(Configuration conf, Options options, String clientClassN this.clientClassName = clientClassName; init(); // set ugi information to hms client - this.clientPool(); + try { + run(client -> null); + } catch (TException e) { + throw new RuntimeException(e); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } } @VisibleForTesting @@ -191,8 +198,7 @@ static Key extractKey(String cacheKeys, Configuration conf, Options options) { switch (type) { case UGI: try { - elements.add( - UserGroupInformationConf.of(UserGroupInformation.getCurrentUser())); + elements.add(UserGroupInformation.getCurrentUser()); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -311,36 +317,6 @@ public static ConfElement of(String key, String value) { } } - static class UserGroupInformationConf { - - private final UserGroupInformation ugi; - - private UserGroupInformationConf(UserGroupInformation ugi) { - this.ugi = ugi; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - UserGroupInformationConf other = (UserGroupInformationConf) obj; - return Objects.equals(other.ugi.getUserName(), ugi.getUserName()); - } - - @Override - public int hashCode() { - return Objects.hash(ugi.getUserName()); - } - - public static UserGroupInformationConf of(UserGroupInformation ugi) { - return new UserGroupInformationConf(ugi); - } - } - private enum KeyElementType { UGI, USER_NAME, diff --git a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/pool/HiveClientPool.java b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/pool/HiveClientPool.java index ca7ccef4cca4..6dd086950771 100644 --- a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/pool/HiveClientPool.java +++ b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/pool/HiveClientPool.java @@ -45,12 +45,6 @@ public HiveClientPool(int poolSize, Configuration conf, String clientClassName) this.hiveConf = new HiveConf(conf, HiveClientPool.class); this.hiveConf.addResource(conf); this.clientClassName = clientClassName; - // set ugi information to hms client - try { - this.run(client -> null); - } catch (Exception e) { - throw new RuntimeException("Failed to connect to Hive Metastore", e); - } } @Override diff --git a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/pool/TestCachedClientPool.java b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/pool/TestCachedClientPool.java index 8898621b29ad..e67439f9bfb2 100644 --- a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/pool/TestCachedClientPool.java +++ b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/pool/TestCachedClientPool.java @@ -99,7 +99,7 @@ public void testCacheKeyUGINotSame() { options1.set("type", "paimon"); options1.set("paimon.catalog.type", "hive"); options1.set("hive.metastore.uris", "thrift://localhost:9083"); - options1.set("client-pool-cache.keys", "ugi,conf:type"); + options1.set("client-pool-cache.keys", "user_name,conf:type"); CachedClientPool cache1 = UserGroupInformation.createRemoteUser("paimon1") @@ -116,7 +116,7 @@ public void testCacheKeyUGINotSame() { options2.set("type", "paimon"); options2.set("paimon.catalog.type", "hive"); options2.set("hive.metastore.uris", "thrift://localhost:9083"); - options2.set("client-pool-cache.keys", "ugi,conf:type"); + options2.set("client-pool-cache.keys", "user_name,conf:type"); CachedClientPool cache2 = UserGroupInformation.createRemoteUser("paimon2") @@ -137,7 +137,7 @@ public void testCacheKeyUGISame() { options.set("type", "paimon"); options.set("paimon.catalog.type", "hive"); options.set("hive.metastore.uris", "thrift://localhost:9083"); - options.set("client-pool-cache.keys", "ugi,conf:type"); + options.set("client-pool-cache.keys", "user_name,conf:type"); // user paimon login CachedClientPool cache1 = @@ -244,7 +244,7 @@ public void testCacheKeyOptionAllNotSame() { options1.set("type", "paimon"); options1.set("paimon.catalog.type", "hive"); options1.set("hive.metastore.uris", "thrift://localhost:9083"); - options1.set("client-pool-cache.keys", "ugi,conf:*"); + options1.set("client-pool-cache.keys", "user_name,conf:*"); CachedClientPool cache1 = UserGroupInformation.createRemoteUser("paimon1") @@ -261,7 +261,7 @@ public void testCacheKeyOptionAllNotSame() { options2.set("type", "hive"); options2.set("paimon.catalog.type", "hive"); options2.set("hive.metastore.uris", "thrift://localhost:9083"); - options2.set("client-pool-cache.keys", "ugi,conf:*"); + options2.set("client-pool-cache.keys", "user_name,conf:*"); CachedClientPool cache2 = UserGroupInformation.createRemoteUser("paimon2") @@ -283,7 +283,7 @@ public void testCacheKeyOptionAllSame() { options.set("type", "paimon"); options.set("paimon.catalog.type", "hive"); options.set("hive.metastore.uris", "thrift://localhost:9083"); - options.set("client-pool-cache.keys", "ugi,conf:type"); + options.set("client-pool-cache.keys", "user_name,conf:type"); // user paimon login CachedClientPool cache1 = @@ -317,7 +317,7 @@ public void testLoginPaimon() throws Exception { options.set("type", "paimon"); options.set("paimon.catalog.type", "hive"); options.set("hive.metastore.uris", "thrift://30.150.24.155:9083"); - options.set("client-pool-cache.keys", "ugi,conf:*"); + options.set("client-pool-cache.keys", "user_name,conf:*"); options.set( "hive.metastore.filter.hook", MockAuthorizationMetaStoreFilterHook.class.getName()); @@ -346,7 +346,7 @@ public void testLoginRoot() throws Exception { options.set("type", "paimon"); options.set("paimon.catalog.type", "hive"); options.set("hive.metastore.uris", "thrift://30.150.24.155:9083"); - options.set("client-pool-cache.keys", "ugi,conf:*"); + options.set("client-pool-cache.keys", "user_name,conf:*"); Configuration config = new Configuration(); config.set("current.user", "root"); @@ -381,7 +381,7 @@ public void testLoginHive() throws Exception { options.set( "hive.metastore.uris", "thrift://30.150.24.155:9083"); - options.set("client-pool-cache.keys", "ugi,conf:*"); + options.set("client-pool-cache.keys", "user_name,conf:*"); // hive config HiveConf hiveConf = new HiveConf(); @@ -462,4 +462,12 @@ private void checkCurrentUser(HiveConf conf) { } } } + + @Test + public void testUgi() throws IOException { + UserGroupInformation user1 = UserGroupInformation.createProxyUser("hive", UserGroupInformation.getCurrentUser()); + UserGroupInformation user2 = UserGroupInformation.createProxyUser("hive", UserGroupInformation.getCurrentUser()); + System.out.println(user1.hashCode()==user2.hashCode()); + System.out.println(user1.equals(user2)); + } }