use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hbase by apache.
the class HRegionServer method getLastFailedRSFromZK.
/**
* Return the last failed RS name under /hbase/recovering-regions/encodedRegionName
* @param encodedRegionName
* @throws KeeperException
*/
private String getLastFailedRSFromZK(String encodedRegionName) throws KeeperException {
String result = null;
long maxZxid = 0;
ZooKeeperWatcher zkw = this.getZooKeeper();
String nodePath = ZKUtil.joinZNode(zkw.znodePaths.recoveringRegionsZNode, encodedRegionName);
List<String> failedServers = ZKUtil.listChildrenNoWatch(zkw, nodePath);
if (failedServers == null || failedServers.isEmpty()) {
return result;
}
for (String failedServer : failedServers) {
String rsPath = ZKUtil.joinZNode(nodePath, failedServer);
Stat stat = new Stat();
ZKUtil.getDataNoWatch(zkw, rsPath, stat);
if (maxZxid < stat.getCzxid()) {
maxZxid = stat.getCzxid();
result = failedServer;
}
}
return result;
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class CuratorService method zkStat.
/**
* Stat the file
* @param path path of operation
* @return a curator stat entry
* @throws IOException on a failure
* @throws PathNotFoundException if the path was not found
*/
public Stat zkStat(String path) throws IOException {
checkServiceLive();
String fullpath = createFullPath(path);
Stat stat;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Stat {}", fullpath);
}
stat = curator.checkExists().forPath(fullpath);
} catch (Exception e) {
throw operationFailure(fullpath, "read()", e);
}
if (stat == null) {
throw new PathNotFoundException(path);
}
return stat;
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class ZKPathDumper method expand.
/**
* Recursively expand the path into the supplied string builder, increasing
* the indentation by {@link #INDENT} as it proceeds (depth first) down
* the tree
* @param builder string build to append to
* @param path path to examine
* @param indent current indentation
*/
private void expand(StringBuilder builder, String path, int indent) {
try {
GetChildrenBuilder childrenBuilder = curator.getChildren();
List<String> children = childrenBuilder.forPath(path);
for (String child : children) {
String childPath = path + "/" + child;
String body;
Stat stat = curator.checkExists().forPath(childPath);
StringBuilder bodyBuilder = new StringBuilder(256);
bodyBuilder.append(" [").append(stat.getDataLength()).append("]");
if (stat.getEphemeralOwner() > 0) {
bodyBuilder.append("*");
}
if (verbose) {
// verbose: extract ACLs
builder.append(" -- ");
List<ACL> acls = curator.getACL().forPath(childPath);
for (ACL acl : acls) {
builder.append(RegistrySecurity.aclToString(acl));
builder.append(" ");
}
}
body = bodyBuilder.toString();
// print each child
append(builder, indent, ' ');
builder.append('/').append(child);
builder.append(body);
builder.append('\n');
// recurse
expand(builder, childPath, indent + INDENT);
}
} catch (Exception e) {
builder.append(e.toString()).append("\n");
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project flink by apache.
the class ZooKeeperLeaderElectionService method writeLeaderInformation.
/**
* Writes the current leader's address as well the given leader session ID to ZooKeeper.
*
* @param leaderSessionID Leader session ID which is written to ZooKeeper
*/
protected void writeLeaderInformation(UUID leaderSessionID) {
// is thread-safe
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Write leader information: Leader={}, session ID={}.", leaderContender.getAddress(), leaderSessionID);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeUTF(leaderContender.getAddress());
oos.writeObject(leaderSessionID);
oos.close();
boolean dataWritten = false;
while (!dataWritten && leaderLatch.hasLeadership()) {
Stat stat = client.checkExists().forPath(leaderPath);
if (stat != null) {
long owner = stat.getEphemeralOwner();
long sessionID = client.getZookeeperClient().getZooKeeper().getSessionId();
if (owner == sessionID) {
try {
client.setData().forPath(leaderPath, baos.toByteArray());
dataWritten = true;
} catch (KeeperException.NoNodeException noNode) {
// node was deleted in the meantime
}
} else {
try {
client.delete().forPath(leaderPath);
} catch (KeeperException.NoNodeException noNode) {
// node was deleted in the meantime --> try again
}
}
} else {
try {
client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(leaderPath, baos.toByteArray());
dataWritten = true;
} catch (KeeperException.NodeExistsException nodeExists) {
// node has been created in the meantime --> try again
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Successfully wrote leader information: Leader={}, session ID={}.", leaderContender.getAddress(), leaderSessionID);
}
} catch (Exception e) {
leaderContender.handleError(new Exception("Could not write leader address and leader session ID to " + "ZooKeeper.", e));
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project hadoop by apache.
the class ZKClient method getServiceData.
/**
* get data published by the service at the registration address
* @param path the path where the service is registered
* @return the data of the registered service
* @throws IOException
* @throws InterruptedException
*/
public String getServiceData(String path) throws IOException, InterruptedException {
String data;
try {
Stat stat = new Stat();
byte[] byteData = zkClient.getData(path, false, stat);
data = new String(byteData, Charset.forName("UTF-8"));
} catch (KeeperException ke) {
throw new IOException(ke);
}
return data;
}
Aggregations