use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class RootTabletLocator method getRootTabletLocation.
protected TabletLocation getRootTabletLocation(ClientContext context) {
Instance instance = context.getInstance();
String zRootLocPath = ZooUtil.getRoot(instance) + RootTable.ZROOT_TABLET_LOCATION;
ZooCache zooCache = zcf.getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
Logger log = LoggerFactory.getLogger(this.getClass());
OpTimer timer = null;
if (log.isTraceEnabled()) {
log.trace("tid={} Looking up root tablet location in zookeeper.", Thread.currentThread().getId());
timer = new OpTimer().start();
}
byte[] loc = zooCache.get(zRootLocPath);
if (timer != null) {
timer.stop();
log.trace("tid={} Found root tablet at {} in {}", Thread.currentThread().getId(), (loc == null ? "null" : new String(loc)), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
}
if (loc == null) {
return null;
}
String[] tokens = new String(loc).split("\\|");
if (lockChecker.isLockHeld(tokens[0], tokens[1]))
return new TabletLocation(RootTable.EXTENT, tokens[0], tokens[1]);
else
return null;
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class RootTabletLocator method invalidateCache.
@Override
public void invalidateCache(Instance instance, String server) {
ZooCache zooCache = zcf.getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
String root = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
zooCache.clear(root + "/" + server);
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class InstanceOperationsImpl method getTabletServers.
@Override
public List<String> getTabletServers() {
Instance instance = context.getInstance();
ZooCache cache = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
List<String> results = new ArrayList<>();
for (String candidate : cache.getChildren(path)) {
List<String> children = cache.getChildren(path + "/" + candidate);
if (children != null && children.size() > 0) {
List<String> copy = new ArrayList<>(children);
Collections.sort(copy);
byte[] data = cache.get(path + "/" + candidate + "/" + copy.get(0));
if (data != null && !"master".equals(new String(data, UTF_8))) {
results.add(candidate);
}
}
}
return results;
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class TabletServerLocks method main.
public static void main(String[] args) throws Exception {
Instance instance = HdfsZooInstance.getInstance();
String tserverPath = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
Opts opts = new Opts();
opts.parseArgs(TabletServerLocks.class.getName(), args);
ZooCache cache = new ZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
if (opts.list) {
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
List<String> tabletServers = zoo.getChildren(tserverPath);
for (String tabletServer : tabletServers) {
byte[] lockData = ZooLock.getLockData(cache, tserverPath + "/" + tabletServer, null);
String holder = null;
if (lockData != null) {
holder = new String(lockData, UTF_8);
}
System.out.printf("%32s %16s%n", tabletServer, holder);
}
} else if (opts.delete != null) {
ZooLock.deleteLock(tserverPath + "/" + args[1]);
} else {
System.out.println("Usage : " + TabletServerLocks.class.getName() + " -list|-delete <tserver lock>");
}
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class BadDeleteMarkersCreatedIT method alterConfig.
@Before
public void alterConfig() throws Exception {
InstanceOperations iops = getConnector().instanceOperations();
Map<String, String> config = iops.getSystemConfiguration();
gcCycleDelay = config.get(Property.GC_CYCLE_DELAY.getKey());
gcCycleStart = config.get(Property.GC_CYCLE_START.getKey());
iops.setProperty(Property.GC_CYCLE_DELAY.getKey(), "1s");
iops.setProperty(Property.GC_CYCLE_START.getKey(), "0s");
log.info("Restarting garbage collector");
getCluster().getClusterControl().stopAllServers(ServerType.GARBAGE_COLLECTOR);
Instance instance = getConnector().getInstance();
ZooCache zcache = new ZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
zcache.clear();
String path = ZooUtil.getRoot(instance) + Constants.ZGC_LOCK;
byte[] gcLockData;
do {
gcLockData = ZooLock.getLockData(zcache, path, null);
if (null != gcLockData) {
log.info("Waiting for GC ZooKeeper lock to expire");
Thread.sleep(2000);
}
} while (null != gcLockData);
log.info("GC lock was lost");
getCluster().getClusterControl().startAllServers(ServerType.GARBAGE_COLLECTOR);
log.info("Garbage collector was restarted");
gcLockData = null;
do {
gcLockData = ZooLock.getLockData(zcache, path, null);
if (null == gcLockData) {
log.info("Waiting for GC ZooKeeper lock to be acquired");
Thread.sleep(2000);
}
} while (null == gcLockData);
log.info("GC lock was acquired");
}
Aggregations