From 83ae477f3d5a42f919d5513f269d3b525eed0a48 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Mon, 29 Apr 2024 11:42:04 +0800 Subject: [PATCH 1/3] HBASE-28555 ThriftConnection does not need ConnectionRegistry --- .../hbase/client/ConnectionFactory.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java index de5981b40412..30ed1f1f594f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java @@ -19,6 +19,7 @@ import static org.apache.hadoop.hbase.util.FutureUtils.addListener; +import com.google.common.base.Throwables; import java.io.IOException; import java.lang.reflect.Constructor; import java.net.URI; @@ -36,6 +37,8 @@ import org.apache.hadoop.hbase.util.FutureUtils; import org.apache.hadoop.hbase.util.ReflectionUtils; import org.apache.yetus.audience.InterfaceAudience; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A non-instantiable class that manages creation of {@link Connection}s. Managing the lifecycle of @@ -74,6 +77,8 @@ @InterfaceAudience.Public public class ConnectionFactory { + private static final Logger LOG = LoggerFactory.getLogger(ConnectionFactory.class); + public static final String HBASE_CLIENT_ASYNC_CONNECTION_IMPL = "hbase.client.async.connection.impl"; @@ -399,15 +404,32 @@ public static Connection createConnection(URI connectionUri, Configuration conf, } catch (ClassNotFoundException e) { throw new IOException(e); } - ConnectionRegistry registry = createConnectionRegistry(connectionUri, conf, user); try { // Default HCM#HCI is not accessible; make it so before invoking. Constructor constructor = clazz.getDeclaredConstructor(Configuration.class, ExecutorService.class, User.class, ConnectionRegistry.class, Map.class); constructor.setAccessible(true); + ConnectionRegistry registry = createConnectionRegistry(connectionUri, conf, user); return user.runAs((PrivilegedExceptionAction) () -> (Connection) constructor .newInstance(conf, pool, user, registry, connectionAttributes)); + } catch (NoSuchMethodException e) { + LOG.debug( + "Constructor with connection registry not found for class {}, fallback to use old constructor", + clazz.getName(), e); + } catch (Exception e) { + Throwables.propagateIfPossible(e, IOException.class); + throw new IOException(e); + } + + try { + // Default HCM#HCI is not accessible; make it so before invoking. + Constructor constructor = clazz.getDeclaredConstructor(Configuration.class, + ExecutorService.class, User.class, Map.class); + constructor.setAccessible(true); + return user.runAs((PrivilegedExceptionAction) () -> (Connection) constructor + .newInstance(conf, pool, user, connectionAttributes)); } catch (Exception e) { + Throwables.propagateIfPossible(e, IOException.class); throw new IOException(e); } }, () -> TraceUtil.createSpan(ConnectionFactory.class.getSimpleName() + ".createConnection")); From 5ffebc3d996b966e321e67448512b29e3be58e0c Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Mon, 29 Apr 2024 12:16:15 +0800 Subject: [PATCH 2/3] fix import --- .../java/org/apache/hadoop/hbase/client/ConnectionFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java index 30ed1f1f594f..1a81526ce3d5 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java @@ -19,7 +19,6 @@ import static org.apache.hadoop.hbase.util.FutureUtils.addListener; -import com.google.common.base.Throwables; import java.io.IOException; import java.lang.reflect.Constructor; import java.net.URI; @@ -40,6 +39,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.com.google.common.base.Throwables; + /** * A non-instantiable class that manages creation of {@link Connection}s. Managing the lifecycle of * the {@link Connection}s to the cluster is the responsibility of the caller. From a From f5b8d3479ce157ae9cf3e0e87af565f3b8a1c714 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Mon, 29 Apr 2024 15:33:32 +0800 Subject: [PATCH 3/3] fix checkstyle --- .../org/apache/hadoop/hbase/client/ConnectionFactory.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java index 1a81526ce3d5..c71b10ef09f0 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionFactory.java @@ -414,9 +414,8 @@ public static Connection createConnection(URI connectionUri, Configuration conf, return user.runAs((PrivilegedExceptionAction) () -> (Connection) constructor .newInstance(conf, pool, user, registry, connectionAttributes)); } catch (NoSuchMethodException e) { - LOG.debug( - "Constructor with connection registry not found for class {}, fallback to use old constructor", - clazz.getName(), e); + LOG.debug("Constructor with connection registry not found for class {}," + + " fallback to use old constructor", clazz.getName(), e); } catch (Exception e) { Throwables.propagateIfPossible(e, IOException.class); throw new IOException(e);