Skip to content

Commit 87deb3a

Browse files
authored
Remove ZooCache from ListInstances command (apache#5267)
ServiceLock.getData uses either a ZooCache or ZooKeeper instance. Changed the utility to use a ZooKeeper instance. Closes apache#5257
1 parent e9a953d commit 87deb3a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

server/base/src/main/java/org/apache/accumulo/server/util/ListInstances.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
import org.apache.accumulo.core.conf.SiteConfiguration;
3434
import org.apache.accumulo.core.data.InstanceId;
3535
import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
36-
import org.apache.accumulo.core.fate.zookeeper.ZooCache;
3736
import org.apache.accumulo.core.fate.zookeeper.ZooReader;
37+
import org.apache.accumulo.core.fate.zookeeper.ZooSession;
38+
import org.apache.zookeeper.ZooKeeper;
3839
import org.slf4j.Logger;
3940
import org.slf4j.LoggerFactory;
4041

@@ -84,23 +85,23 @@ static synchronized void listInstances(String keepers, boolean printAll, boolean
8485

8586
System.out.println("INFO : Using ZooKeepers " + keepers);
8687
ZooReader rdr = new ZooReader(keepers, ZOOKEEPER_TIMER_MILLIS);
87-
ZooCache cache = new ZooCache(rdr, null);
88+
ZooKeeper zk = ZooSession.getAnonymousSession(keepers, ZOOKEEPER_TIMER_MILLIS);
8889

8990
TreeMap<String,InstanceId> instanceNames = getInstanceNames(rdr, printErrors);
9091

9192
System.out.println();
9293
printHeader();
9394

9495
for (Entry<String,InstanceId> entry : instanceNames.entrySet()) {
95-
printInstanceInfo(cache, entry.getKey(), entry.getValue(), printErrors);
96+
printInstanceInfo(zk, entry.getKey(), entry.getValue(), printErrors);
9697
}
9798

9899
TreeSet<InstanceId> instancedIds = getInstanceIDs(rdr, printErrors);
99100
instancedIds.removeAll(instanceNames.values());
100101

101102
if (printAll) {
102103
for (InstanceId uuid : instancedIds) {
103-
printInstanceInfo(cache, null, uuid, printErrors);
104+
printInstanceInfo(zk, null, uuid, printErrors);
104105
}
105106
} else if (!instancedIds.isEmpty()) {
106107
System.out.println();
@@ -140,9 +141,9 @@ private static void printHeader() {
140141

141142
}
142143

143-
private static void printInstanceInfo(ZooCache cache, String instanceName, InstanceId iid,
144+
private static void printInstanceInfo(ZooKeeper zk, String instanceName, InstanceId iid,
144145
boolean printErrors) {
145-
String manager = getManager(cache, iid, printErrors);
146+
String manager = getManager(zk, iid, printErrors);
146147
if (instanceName == null) {
147148
instanceName = "";
148149
}
@@ -155,7 +156,7 @@ private static void printInstanceInfo(ZooCache cache, String instanceName, Insta
155156
"\"" + instanceName + "\"", iid, manager);
156157
}
157158

158-
private static String getManager(ZooCache cache, InstanceId iid, boolean printErrors) {
159+
private static String getManager(ZooKeeper zk, InstanceId iid, boolean printErrors) {
159160

160161
if (iid == null) {
161162
return null;
@@ -164,7 +165,7 @@ private static String getManager(ZooCache cache, InstanceId iid, boolean printEr
164165
try {
165166
var zLockManagerPath =
166167
ServiceLock.path(Constants.ZROOT + "/" + iid + Constants.ZMANAGER_LOCK);
167-
byte[] manager = ServiceLock.getLockData(cache, zLockManagerPath, null);
168+
byte[] manager = ServiceLock.getLockData(zk, zLockManagerPath);
168169
if (manager == null) {
169170
return null;
170171
}

0 commit comments

Comments
 (0)