Skip to content

Commit 095617f

Browse files
lokiorelokesh-khurana
and
lokesh-khurana
authored
PHOENIX-7464 :- Performance Regression in Connection Initialization due to Configuration Handling in ConnInfo (#2027)
Co-authored-by: lokesh-khurana <[email protected]>
1 parent 5a3a4a8 commit 095617f

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/ConnectionInfo.java

+42-12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ public abstract class ConnectionInfo {
5959
protected static final boolean HAS_MASTER_REGISTRY;
6060
protected static final boolean HAS_RPC_REGISTRY;
6161

62+
private static volatile Configuration configuration;
63+
64+
public static Configuration getCachedConfiguration() {
65+
if (configuration == null) {
66+
synchronized (ConnectionInfo.class) {
67+
if (configuration == null) {
68+
configuration = HBaseFactoryProvider.getConfigurationFactory().getConfiguration();
69+
}
70+
}
71+
}
72+
return configuration;
73+
}
74+
6275
static {
6376
String version = VersionInfo.getVersion();
6477
if (VersionInfo.getMajorVersion(version) >= 3) {
@@ -107,14 +120,12 @@ protected static String unescape(String escaped) {
107120

108121
public static ConnectionInfo createNoLogin(String url, ReadOnlyProps props, Properties info)
109122
throws SQLException {
110-
Configuration conf = HBaseFactoryProvider.getConfigurationFactory().getConfiguration();
111-
return create(url, conf, props, info, true);
123+
return create(url, getCachedConfiguration(), props, info, true);
112124
}
113125

114126
public static ConnectionInfo create(String url, ReadOnlyProps props, Properties info)
115127
throws SQLException {
116-
Configuration conf = HBaseFactoryProvider.getConfigurationFactory().getConfiguration();
117-
return create(url, conf, props, info);
128+
return create(url, getCachedConfiguration(), props, info);
118129
}
119130

120131
public static ConnectionInfo createNoLogin(String url, Configuration configuration,
@@ -482,15 +493,10 @@ protected void handleKerberosAndLogin() throws SQLException {
482493
LOGGER.info("Trying to connect to a secure cluster as {} "
483494
+ "with keytab {}",
484495
principal, keytab);
496+
final Configuration newConfig = getConfiguration(principal, keytab);
485497
// We are intentionally changing the passed in Configuration object
486-
if (null != principal) {
487-
config.set(QueryServices.HBASE_CLIENT_PRINCIPAL, principal);
488-
}
489-
if (null != keytab) {
490-
config.set(QueryServices.HBASE_CLIENT_KEYTAB, keytab);
491-
}
492-
UserGroupInformation.setConfiguration(config);
493-
User.login(config, QueryServices.HBASE_CLIENT_KEYTAB,
498+
UserGroupInformation.setConfiguration(newConfig);
499+
User.login(newConfig, QueryServices.HBASE_CLIENT_KEYTAB,
494500
QueryServices.HBASE_CLIENT_PRINCIPAL, null);
495501
user = User.getCurrent();
496502
LOGGER.info("Successful login to secure cluster");
@@ -510,6 +516,30 @@ protected void handleKerberosAndLogin() throws SQLException {
510516
}
511517
}
512518

519+
private Configuration getConfiguration( String principal, String keytab) {
520+
final Configuration config = HBaseFactoryProvider.getConfigurationFactory().getConfiguration();
521+
// Add QueryServices properties
522+
if (props != null) {
523+
for (Entry<String,String> entry : props) {
524+
config.set(entry.getKey(), entry.getValue());
525+
}
526+
}
527+
// Add any user-provided properties (via DriverManager)
528+
if (info != null) {
529+
for (Object key : info.keySet()) {
530+
config.set((String) key, info.getProperty((String) key));
531+
}
532+
}
533+
// Set the principal and keytab if provided from the URL (overriding those provided in Properties)
534+
if (null != principal) {
535+
config.set(QueryServices.HBASE_CLIENT_PRINCIPAL, principal);
536+
}
537+
if (null != keytab) {
538+
config.set(QueryServices.HBASE_CLIENT_KEYTAB, keytab);
539+
}
540+
return config;
541+
}
542+
513543
protected String normalizeHostsList(String quorum, Integer defaultPort)
514544
throws SQLException {
515545
// The input host:port separator char is "=" (after unescaping)

0 commit comments

Comments
 (0)