Skip to content

Commit

Permalink
[hive] bugfix jdbc paimon hive client pool (apache#3004)
Browse files Browse the repository at this point in the history
  • Loading branch information
坤泰 committed Aug 22, 2024
1 parent 358a07e commit 6c82e52
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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 =
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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 =
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 6c82e52

Please sign in to comment.