@@ -100,13 +100,14 @@ public void process(WatchedEvent event) {
100
100
}
101
101
102
102
/**
103
- * @param host comma separated list of zk servers
103
+ * @param connectString in the form of host1:port1,host2:port2/chroot/path
104
104
* @param timeout in milliseconds
105
105
* @param scheme authentication type, e.g. 'digest', may be null
106
106
* @param auth authentication-scheme-specific token, may be null
107
107
* @param watcher ZK notifications, may be null
108
108
*/
109
- static ZooKeeper connect (String host , int timeout , String scheme , byte [] auth , Watcher watcher ) {
109
+ static ZooKeeper connect (String connectString , int timeout , String scheme , byte [] auth ,
110
+ Watcher watcher ) {
110
111
final int TIME_BETWEEN_CONNECT_CHECKS_MS = 100 ;
111
112
int connectTimeWait = Math .min (10_000 , timeout );
112
113
boolean tryAgain = true ;
@@ -117,7 +118,7 @@ static ZooKeeper connect(String host, int timeout, String scheme, byte[] auth, W
117
118
118
119
while (tryAgain ) {
119
120
try {
120
- zooKeeper = new ZooKeeper (host , timeout , watcher );
121
+ zooKeeper = new ZooKeeper (connectString , timeout , watcher );
121
122
// it may take some time to get connected to zookeeper if some of the servers are down
122
123
for (int i = 0 ; i < connectTimeWait / TIME_BETWEEN_CONNECT_CHECKS_MS && tryAgain ; i ++) {
123
124
if (zooKeeper .getState ().equals (States .CONNECTED )) {
@@ -155,7 +156,7 @@ static ZooKeeper connect(String host, int timeout, String scheme, byte[] auth, W
155
156
long duration = NANOSECONDS .toMillis (stopTime - startTime );
156
157
157
158
if (duration > 2L * timeout ) {
158
- throw new IllegalStateException ("Failed to connect to zookeeper (" + host
159
+ throw new IllegalStateException ("Failed to connect to zookeeper (" + connectString
159
160
+ ") within 2x zookeeper timeout period " + timeout );
160
161
}
161
162
@@ -177,16 +178,16 @@ static ZooKeeper connect(String host, int timeout, String scheme, byte[] auth, W
177
178
return zooKeeper ;
178
179
}
179
180
180
- public static ZooKeeper getAuthenticatedSession (String zooKeepers , int timeout , String scheme ,
181
+ public static ZooKeeper getAuthenticatedSession (String connectString , int timeout , String scheme ,
181
182
byte [] auth ) {
182
- return getSession (zooKeepers , timeout , scheme , auth );
183
+ return getSession (connectString , timeout , scheme , auth );
183
184
}
184
185
185
- public static ZooKeeper getAnonymousSession (String zooKeepers , int timeout ) {
186
- return getSession (zooKeepers , timeout , null , null );
186
+ public static ZooKeeper getAnonymousSession (String connectString , int timeout ) {
187
+ return getSession (connectString , timeout , null , null );
187
188
}
188
189
189
- private static synchronized ZooKeeper getSession (String zooKeepers , int timeout , String scheme ,
190
+ private static synchronized ZooKeeper getSession (String connectString , int timeout , String scheme ,
190
191
byte [] auth ) {
191
192
192
193
if (sessions == null ) {
@@ -195,13 +196,13 @@ private static synchronized ZooKeeper getSession(String zooKeepers, int timeout,
195
196
+ "caused by all AccumuloClients being closed or garbage collected." );
196
197
}
197
198
198
- String sessionKey = sessionKey (zooKeepers , timeout , scheme , auth );
199
+ String sessionKey = sessionKey (connectString , timeout , scheme , auth );
199
200
200
201
// a read-only session can use a session with authorizations, so cache a copy for it w/out auths
201
- String readOnlySessionKey = sessionKey (zooKeepers , timeout , null , null );
202
+ String readOnlySessionKey = sessionKey (connectString , timeout , null , null );
202
203
ZooSessionInfo zsi = sessions .get (sessionKey );
203
204
if (zsi != null && zsi .zooKeeper .getState () == States .CLOSED ) {
204
- log .debug ("Removing closed ZooKeeper session to {}" , zooKeepers );
205
+ log .debug ("Removing closed ZooKeeper session to {}" , connectString );
205
206
if (auth != null && sessions .get (readOnlySessionKey ) == zsi ) {
206
207
sessions .remove (readOnlySessionKey );
207
208
}
@@ -211,8 +212,8 @@ private static synchronized ZooKeeper getSession(String zooKeepers, int timeout,
211
212
212
213
if (zsi == null ) {
213
214
ZooWatcher watcher = new ZooWatcher ();
214
- log .debug ("Connecting to {} with timeout {} with auth" , zooKeepers , timeout );
215
- zsi = new ZooSessionInfo (connect (zooKeepers , timeout , scheme , auth , watcher ));
215
+ log .debug ("Connecting to {} with timeout {} with auth" , connectString , timeout );
216
+ zsi = new ZooSessionInfo (connect (connectString , timeout , scheme , auth , watcher ));
216
217
sessions .put (sessionKey , zsi );
217
218
if (auth != null && !sessions .containsKey (readOnlySessionKey )) {
218
219
sessions .put (readOnlySessionKey , zsi );
0 commit comments