@@ -59,6 +59,19 @@ public abstract class ConnectionInfo {
59
59
protected static final boolean HAS_MASTER_REGISTRY ;
60
60
protected static final boolean HAS_RPC_REGISTRY ;
61
61
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
+
62
75
static {
63
76
String version = VersionInfo .getVersion ();
64
77
if (VersionInfo .getMajorVersion (version ) >= 3 ) {
@@ -107,14 +120,12 @@ protected static String unescape(String escaped) {
107
120
108
121
public static ConnectionInfo createNoLogin (String url , ReadOnlyProps props , Properties info )
109
122
throws SQLException {
110
- Configuration conf = HBaseFactoryProvider .getConfigurationFactory ().getConfiguration ();
111
- return create (url , conf , props , info , true );
123
+ return create (url , getCachedConfiguration (), props , info , true );
112
124
}
113
125
114
126
public static ConnectionInfo create (String url , ReadOnlyProps props , Properties info )
115
127
throws SQLException {
116
- Configuration conf = HBaseFactoryProvider .getConfigurationFactory ().getConfiguration ();
117
- return create (url , conf , props , info );
128
+ return create (url , getCachedConfiguration (), props , info );
118
129
}
119
130
120
131
public static ConnectionInfo createNoLogin (String url , Configuration configuration ,
@@ -482,15 +493,10 @@ protected void handleKerberosAndLogin() throws SQLException {
482
493
LOGGER .info ("Trying to connect to a secure cluster as {} "
483
494
+ "with keytab {}" ,
484
495
principal , keytab );
496
+ final Configuration newConfig = getConfiguration (principal , keytab );
485
497
// 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 ,
494
500
QueryServices .HBASE_CLIENT_PRINCIPAL , null );
495
501
user = User .getCurrent ();
496
502
LOGGER .info ("Successful login to secure cluster" );
@@ -510,6 +516,30 @@ protected void handleKerberosAndLogin() throws SQLException {
510
516
}
511
517
}
512
518
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
+
513
543
protected String normalizeHostsList (String quorum , Integer defaultPort )
514
544
throws SQLException {
515
545
// The input host:port separator char is "=" (after unescaping)
0 commit comments