Search in sources :

Example 11 with Stat

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;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)

Example 12 with Stat

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;
}
Also used : Stat(org.apache.zookeeper.data.Stat) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) NoChildrenForEphemeralsException(org.apache.hadoop.registry.client.exceptions.NoChildrenForEphemeralsException) AuthenticationFailedException(org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) KeeperException(org.apache.zookeeper.KeeperException) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) IOException(java.io.IOException) RegistryIOException(org.apache.hadoop.registry.client.exceptions.RegistryIOException) PathIsNotEmptyDirectoryException(org.apache.hadoop.fs.PathIsNotEmptyDirectoryException) ServiceStateException(org.apache.hadoop.service.ServiceStateException) NoPathPermissionsException(org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException)

Example 13 with 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");
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) ACL(org.apache.zookeeper.data.ACL)

Example 14 with Stat

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));
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException)

Example 15 with Stat

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;
}
Also used : Stat(org.apache.zookeeper.data.Stat) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

Stat (org.apache.zookeeper.data.Stat)799 KeeperException (org.apache.zookeeper.KeeperException)266 Test (org.junit.Test)124 IOException (java.io.IOException)120 ZooKeeper (org.apache.zookeeper.ZooKeeper)88 ArrayList (java.util.ArrayList)67 Test (org.testng.annotations.Test)58 Test (org.junit.jupiter.api.Test)53 Watcher (org.apache.zookeeper.Watcher)49 AsyncCallback (org.apache.zookeeper.AsyncCallback)48 ACL (org.apache.zookeeper.data.ACL)47 List (java.util.List)43 CountDownLatch (java.util.concurrent.CountDownLatch)43 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 CuratorFramework (org.apache.curator.framework.CuratorFramework)37 Map (java.util.Map)34 HashMap (java.util.HashMap)32 WebApplicationException (javax.ws.rs.WebApplicationException)29 ExecutionException (java.util.concurrent.ExecutionException)27