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..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 @@ -36,6 +36,10 @@ 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; + +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 @@ -74,6 +78,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 +405,31 @@ 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"));