Skip to content

Commit d90dfc3

Browse files
Change names of zookeepers to connectString (apache#5092)
Trivial change to zookeepers parameter to indicate that it's a connectionString rather than merely a host or a list of hosts for zookeeper. Co-authored-by: meatballspaghetti <69256191+meatballspaghetti@users.noreply.github.com>
1 parent 5b2bb6e commit d90dfc3

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ZooReader.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ public class ZooReader {
4545
.incrementBy(Duration.ofMillis(250)).maxWait(Duration.ofMinutes(2)).backOffFactor(1.5)
4646
.logInterval(Duration.ofMinutes(3)).createFactory();
4747

48-
protected final String keepers;
48+
protected final String connectString;
4949
protected final int timeout;
5050

51-
public ZooReader(String keepers, int timeout) {
52-
this.keepers = requireNonNull(keepers);
51+
public ZooReader(String connectString, int timeout) {
52+
this.connectString = requireNonNull(connectString);
5353
this.timeout = timeout;
5454
}
5555

5656
public ZooReaderWriter asWriter(String secret) {
57-
return new ZooReaderWriter(keepers, timeout, secret);
57+
return new ZooReaderWriter(connectString, timeout, secret);
5858
}
5959

6060
protected ZooKeeper getZooKeeper() {
61-
return ZooSession.getAnonymousSession(keepers, timeout);
61+
return ZooSession.getAnonymousSession(connectString, timeout);
6262
}
6363

6464
protected RetryFactory getRetryFactory() {

core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ZooReaderWriter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public ZooReaderWriter(AccumuloConfiguration conf) {
4949
private final String secret;
5050
private final byte[] auth;
5151

52-
ZooReaderWriter(String keepers, int timeoutInMillis, String secret) {
53-
super(keepers, timeoutInMillis);
52+
ZooReaderWriter(String connectString, int timeoutInMillis, String secret) {
53+
super(connectString, timeoutInMillis);
5454
this.secret = requireNonNull(secret);
5555
this.auth = ("accumulo:" + secret).getBytes(UTF_8);
5656
}
@@ -65,7 +65,7 @@ public ZooReaderWriter asWriter(String secret) {
6565

6666
@Override
6767
public ZooKeeper getZooKeeper() {
68-
return ZooSession.getAuthenticatedSession(keepers, timeout, "digest", auth);
68+
return ZooSession.getAuthenticatedSession(connectString, timeout, "digest", auth);
6969
}
7070

7171
/**

core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ZooSession.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ public void process(WatchedEvent event) {
100100
}
101101

102102
/**
103-
* @param host comma separated list of zk servers
103+
* @param connectString in the form of host1:port1,host2:port2/chroot/path
104104
* @param timeout in milliseconds
105105
* @param scheme authentication type, e.g. 'digest', may be null
106106
* @param auth authentication-scheme-specific token, may be null
107107
* @param watcher ZK notifications, may be null
108108
*/
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) {
110111
final int TIME_BETWEEN_CONNECT_CHECKS_MS = 100;
111112
int connectTimeWait = Math.min(10_000, timeout);
112113
boolean tryAgain = true;
@@ -117,7 +118,7 @@ static ZooKeeper connect(String host, int timeout, String scheme, byte[] auth, W
117118

118119
while (tryAgain) {
119120
try {
120-
zooKeeper = new ZooKeeper(host, timeout, watcher);
121+
zooKeeper = new ZooKeeper(connectString, timeout, watcher);
121122
// it may take some time to get connected to zookeeper if some of the servers are down
122123
for (int i = 0; i < connectTimeWait / TIME_BETWEEN_CONNECT_CHECKS_MS && tryAgain; i++) {
123124
if (zooKeeper.getState().equals(States.CONNECTED)) {
@@ -155,7 +156,7 @@ static ZooKeeper connect(String host, int timeout, String scheme, byte[] auth, W
155156
long duration = NANOSECONDS.toMillis(stopTime - startTime);
156157

157158
if (duration > 2L * timeout) {
158-
throw new IllegalStateException("Failed to connect to zookeeper (" + host
159+
throw new IllegalStateException("Failed to connect to zookeeper (" + connectString
159160
+ ") within 2x zookeeper timeout period " + timeout);
160161
}
161162

@@ -177,16 +178,16 @@ static ZooKeeper connect(String host, int timeout, String scheme, byte[] auth, W
177178
return zooKeeper;
178179
}
179180

180-
public static ZooKeeper getAuthenticatedSession(String zooKeepers, int timeout, String scheme,
181+
public static ZooKeeper getAuthenticatedSession(String connectString, int timeout, String scheme,
181182
byte[] auth) {
182-
return getSession(zooKeepers, timeout, scheme, auth);
183+
return getSession(connectString, timeout, scheme, auth);
183184
}
184185

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);
187188
}
188189

189-
private static synchronized ZooKeeper getSession(String zooKeepers, int timeout, String scheme,
190+
private static synchronized ZooKeeper getSession(String connectString, int timeout, String scheme,
190191
byte[] auth) {
191192

192193
if (sessions == null) {
@@ -195,13 +196,13 @@ private static synchronized ZooKeeper getSession(String zooKeepers, int timeout,
195196
+ "caused by all AccumuloClients being closed or garbage collected.");
196197
}
197198

198-
String sessionKey = sessionKey(zooKeepers, timeout, scheme, auth);
199+
String sessionKey = sessionKey(connectString, timeout, scheme, auth);
199200

200201
// 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);
202203
ZooSessionInfo zsi = sessions.get(sessionKey);
203204
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);
205206
if (auth != null && sessions.get(readOnlySessionKey) == zsi) {
206207
sessions.remove(readOnlySessionKey);
207208
}
@@ -211,8 +212,8 @@ private static synchronized ZooKeeper getSession(String zooKeepers, int timeout,
211212

212213
if (zsi == null) {
213214
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));
216217
sessions.put(sessionKey, zsi);
217218
if (auth != null && !sessions.containsKey(readOnlySessionKey)) {
218219
sessions.put(readOnlySessionKey, zsi);

0 commit comments

Comments
 (0)