Skip to content

Commit

Permalink
Remove ZooCache from ListInstances command (apache#5267)
Browse files Browse the repository at this point in the history
ServiceLock.getData uses either a ZooCache or ZooKeeper
instance. Changed the utility to use a ZooKeeper instance.

Closes apache#5257
  • Loading branch information
dlmarion authored Jan 17, 2025
1 parent e9a953d commit 87deb3a
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import org.apache.accumulo.core.conf.SiteConfiguration;
import org.apache.accumulo.core.data.InstanceId;
import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
import org.apache.accumulo.core.fate.zookeeper.ZooCache;
import org.apache.accumulo.core.fate.zookeeper.ZooReader;
import org.apache.accumulo.core.fate.zookeeper.ZooSession;
import org.apache.zookeeper.ZooKeeper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

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

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

System.out.println();
printHeader();

for (Entry<String,InstanceId> entry : instanceNames.entrySet()) {
printInstanceInfo(cache, entry.getKey(), entry.getValue(), printErrors);
printInstanceInfo(zk, entry.getKey(), entry.getValue(), printErrors);
}

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

if (printAll) {
for (InstanceId uuid : instancedIds) {
printInstanceInfo(cache, null, uuid, printErrors);
printInstanceInfo(zk, null, uuid, printErrors);
}
} else if (!instancedIds.isEmpty()) {
System.out.println();
Expand Down Expand Up @@ -140,9 +141,9 @@ private static void printHeader() {

}

private static void printInstanceInfo(ZooCache cache, String instanceName, InstanceId iid,
private static void printInstanceInfo(ZooKeeper zk, String instanceName, InstanceId iid,
boolean printErrors) {
String manager = getManager(cache, iid, printErrors);
String manager = getManager(zk, iid, printErrors);
if (instanceName == null) {
instanceName = "";
}
Expand All @@ -155,7 +156,7 @@ private static void printInstanceInfo(ZooCache cache, String instanceName, Insta
"\"" + instanceName + "\"", iid, manager);
}

private static String getManager(ZooCache cache, InstanceId iid, boolean printErrors) {
private static String getManager(ZooKeeper zk, InstanceId iid, boolean printErrors) {

if (iid == null) {
return null;
Expand All @@ -164,7 +165,7 @@ private static String getManager(ZooCache cache, InstanceId iid, boolean printEr
try {
var zLockManagerPath =
ServiceLock.path(Constants.ZROOT + "/" + iid + Constants.ZMANAGER_LOCK);
byte[] manager = ServiceLock.getLockData(cache, zLockManagerPath, null);
byte[] manager = ServiceLock.getLockData(zk, zLockManagerPath);
if (manager == null) {
return null;
}
Expand Down

0 comments on commit 87deb3a

Please sign in to comment.