use of org.apache.accumulo.fate.zookeeper.ZooCache.ZcStat in project accumulo by apache.
the class ZooCacheTest method testGet.
private void testGet(boolean fillStat) throws Exception {
ZcStat myStat = null;
if (fillStat) {
myStat = new ZcStat();
}
final long ephemeralOwner = 123456789L;
Stat existsStat = new Stat();
existsStat.setEphemeralOwner(ephemeralOwner);
expect(zk.exists(eq(ZPATH), anyObject(Watcher.class))).andReturn(existsStat);
expect(zk.getData(eq(ZPATH), anyObject(Watcher.class), eq(existsStat))).andReturn(DATA);
replay(zk);
assertFalse(zc.dataCached(ZPATH));
assertArrayEquals(DATA, (fillStat ? zc.get(ZPATH, myStat) : zc.get(ZPATH)));
verify(zk);
if (fillStat) {
assertEquals(ephemeralOwner, myStat.getEphemeralOwner());
}
assertTrue(zc.dataCached(ZPATH));
// cache hit
assertSame(DATA, zc.get(ZPATH));
}
use of org.apache.accumulo.fate.zookeeper.ZooCache.ZcStat in project accumulo by apache.
the class AdminTest method testQualifySessionId.
@Test
public void testQualifySessionId() {
ZooCache zc = EasyMock.createMock(ZooCache.class);
String root = "/accumulo/id/tservers";
String server = "localhost:12345";
final long session = 123456789l;
String serverPath = root + "/" + server;
EasyMock.expect(zc.getChildren(serverPath)).andReturn(Collections.singletonList("child"));
EasyMock.expect(zc.get(EasyMock.eq(serverPath + "/child"), EasyMock.anyObject(ZcStat.class))).andAnswer(new IAnswer<byte[]>() {
@Override
public byte[] answer() throws Throwable {
ZcStat stat = (ZcStat) EasyMock.getCurrentArguments()[1];
stat.setEphemeralOwner(session);
return new byte[0];
}
});
EasyMock.replay(zc);
assertEquals(server + "[" + Long.toHexString(session) + "]", Admin.qualifyWithZooKeeperSessionId(root, zc, server));
EasyMock.verify(zc);
}
use of org.apache.accumulo.fate.zookeeper.ZooCache.ZcStat in project accumulo by apache.
the class ZooLock method isLockHeld.
public static boolean isLockHeld(ZooCache zc, LockID lid) {
List<String> children = zc.getChildren(lid.path);
if (children == null || children.size() == 0) {
return false;
}
children = new ArrayList<>(children);
Collections.sort(children);
String lockNode = children.get(0);
if (!lid.node.equals(lockNode))
return false;
ZcStat stat = new ZcStat();
return zc.get(lid.path + "/" + lid.node, stat) != null && stat.getEphemeralOwner() == lid.eid;
}
use of org.apache.accumulo.fate.zookeeper.ZooCache.ZcStat in project accumulo by apache.
the class LiveTServerSet method checkServer.
private synchronized void checkServer(final Set<TServerInstance> updates, final Set<TServerInstance> doomed, final String path, final String zPath) throws TException, InterruptedException, KeeperException {
TServerInfo info = current.get(zPath);
final String lockPath = path + "/" + zPath;
ZcStat stat = new ZcStat();
byte[] lockData = ZooLock.getLockData(getZooCache(), lockPath, stat);
if (lockData == null) {
if (info != null) {
doomed.add(info.instance);
current.remove(zPath);
currentInstances.remove(info.instance);
}
Long firstSeen = locklessServers.get(zPath);
if (firstSeen == null) {
locklessServers.put(zPath, System.currentTimeMillis());
} else if (System.currentTimeMillis() - firstSeen > 10 * 60 * 1000) {
deleteServerNode(path + "/" + zPath);
locklessServers.remove(zPath);
}
} else {
locklessServers.remove(zPath);
ServerServices services = new ServerServices(new String(lockData, UTF_8));
HostAndPort client = services.getAddress(ServerServices.Service.TSERV_CLIENT);
TServerInstance instance = new TServerInstance(client, stat.getEphemeralOwner());
if (info == null) {
updates.add(instance);
TServerInfo tServerInfo = new TServerInfo(instance, new TServerConnection(client));
current.put(zPath, tServerInfo);
currentInstances.put(instance, tServerInfo);
} else if (!info.instance.equals(instance)) {
doomed.add(info.instance);
updates.add(instance);
TServerInfo tServerInfo = new TServerInfo(instance, new TServerConnection(client));
current.put(zPath, tServerInfo);
currentInstances.remove(info.instance);
currentInstances.put(instance, tServerInfo);
}
}
}
use of org.apache.accumulo.fate.zookeeper.ZooCache.ZcStat in project accumulo by apache.
the class ZooLock method getSessionId.
public static long getSessionId(ZooCache zc, String path) throws KeeperException, InterruptedException {
List<String> children = zc.getChildren(path);
if (children == null || children.size() == 0) {
return 0;
}
children = new ArrayList<>(children);
Collections.sort(children);
String lockNode = children.get(0);
ZcStat stat = new ZcStat();
if (zc.get(path + "/" + lockNode, stat) != null)
return stat.getEphemeralOwner();
return 0;
}
Aggregations