use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project storm by apache.
the class Zookeeper method getVersion.
public static Integer getVersion(CuratorFramework zk, String path, boolean watch) throws Exception {
String npath = normalizePath(path);
Stat stat = null;
if (existsNode(zk, npath, watch)) {
if (watch) {
stat = zk.checkExists().watched().forPath(npath);
} else {
stat = zk.checkExists().forPath(npath);
}
}
return stat == null ? null : Integer.valueOf(stat.getVersion());
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hbase by apache.
the class MasterAddressTracker method deleteIfEquals.
/**
* delete the master znode if its content is same as the parameter
* @param zkw must not be null
* @param content must not be null
*/
public static boolean deleteIfEquals(ZooKeeperWatcher zkw, final String content) {
if (content == null) {
throw new IllegalArgumentException("Content must not be null");
}
try {
Stat stat = new Stat();
byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.znodePaths.masterAddressZNode, stat);
ServerName sn = ProtobufUtil.parseServerNameFrom(data);
if (sn != null && content.equals(sn.toString())) {
return (ZKUtil.deleteNode(zkw, zkw.znodePaths.masterAddressZNode, stat.getVersion()));
}
} catch (KeeperException e) {
LOG.warn("Can't get or delete the master znode", e);
} catch (DeserializationException e) {
LOG.warn("Can't get or delete the master znode", e);
}
return false;
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hbase by apache.
the class ZKUtil method watchAndCheckExists.
//
// Existence checks and watches
//
/**
* Watch the specified znode for delete/create/change events. The watcher is
* set whether or not the node exists. If the node already exists, the method
* returns true. If the node does not exist, the method returns false.
*
* @param zkw zk reference
* @param znode path of node to watch
* @return true if znode exists, false if does not exist or error
* @throws KeeperException if unexpected zookeeper exception
*/
public static boolean watchAndCheckExists(ZooKeeperWatcher zkw, String znode) throws KeeperException {
try {
Stat s = zkw.getRecoverableZooKeeper().exists(znode, zkw);
boolean exists = s != null ? true : false;
if (exists) {
LOG.debug(zkw.prefix("Set watcher on existing znode=" + znode));
} else {
LOG.debug(zkw.prefix("Set watcher on znode that does not yet exist, " + znode));
}
return exists;
} catch (KeeperException e) {
LOG.warn(zkw.prefix("Unable to set watcher on znode " + znode), e);
zkw.keeperException(e);
return false;
} catch (InterruptedException e) {
LOG.warn(zkw.prefix("Unable to set watcher on znode " + znode), e);
zkw.interruptedException(e);
return false;
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hbase by apache.
the class ZKUtil method createAndWatch.
/**
* Creates the specified node with the specified data and watches it.
*
* <p>Throws an exception if the node already exists.
*
* <p>The node created is persistent and open access.
*
* <p>Returns the version number of the created node if successful.
*
* @param zkw zk reference
* @param znode path of node to create
* @param data data of node to create
* @return version of node created
* @throws KeeperException if unexpected zookeeper exception
* @throws KeeperException.NodeExistsException if node already exists
*/
public static int createAndWatch(ZooKeeperWatcher zkw, String znode, byte[] data) throws KeeperException, KeeperException.NodeExistsException {
try {
zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode), CreateMode.PERSISTENT);
Stat stat = zkw.getRecoverableZooKeeper().exists(znode, zkw);
if (stat == null) {
// Likely a race condition. Someone deleted the znode.
throw KeeperException.create(KeeperException.Code.SYSTEMERROR, "ZK.exists returned null (i.e.: znode does not exist) for znode=" + znode);
}
return stat.getVersion();
} catch (InterruptedException e) {
zkw.interruptedException(e);
return -1;
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project zookeeper by apache.
the class QuorumRequestPipelineTest method testExists.
@Test
public void testExists() throws Exception {
Stat stat = create2EmptyNode(zkClient, PARENT_PATH);
Assert.assertEquals(String.format("%s Exists returns correct node stat", serverState), stat, zkClient.exists(PARENT_PATH, false));
}
Aggregations