Search in sources :

Example 96 with KeeperException

use of org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.

the class DHTRingCurTargetZK method setRingAndVersionPair.

private void setRingAndVersionPair(String ringName, long ringConfigVersion, long configInstanceVersion, String path) throws KeeperException {
    int attemptIndex;
    boolean complete;
    attemptIndex = 0;
    complete = false;
    while (!complete) {
        try {
            Stat stat;
            if (!mc.getZooKeeper().exists(path)) {
                mc.getZooKeeper().create(path);
            }
            stat = mc.getZooKeeper().set(path, nameAndVersionToBytes(ringName, ringConfigVersion, configInstanceVersion));
            if (debug) {
                Log.warning(path);
                Log.warning(stat);
            }
            complete = true;
        } catch (KeeperException ke) {
            Log.logErrorWarning(ke, "Exception in DHTRingCurTargetZK.setRingAndVersion(). Attempt: " + attemptIndex);
            if (attemptIndex >= retries) {
                throw ke;
            } else {
                ++attemptIndex;
                ThreadUtil.randomSleep(retrySleepMS, retrySleepMS << attemptIndex);
            }
        }
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException)

Example 97 with KeeperException

use of org.apache.zookeeper.KeeperException in project bookkeeper by apache.

the class DLMetadata method create.

public void create(URI uri) throws IOException {
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
    byte[] data = serialize();
    try {
        Utils.zkCreateFullPathOptimistic(zkc, uri.getPath(), data, zkc.getDefaultACL(), CreateMode.PERSISTENT);
    } catch (KeeperException ke) {
        throw new ZKException("Encountered zookeeper exception on creating dl metadata", ke);
    } finally {
        zkc.close();
    }
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) KeeperException(org.apache.zookeeper.KeeperException)

Example 98 with KeeperException

use of org.apache.zookeeper.KeeperException in project bookkeeper by apache.

the class DLMetadata method update.

public void update(URI uri) throws IOException {
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
    byte[] data = serialize();
    try {
        zkc.get().setData(uri.getPath(), data, -1);
    } catch (KeeperException e) {
        throw new IOException("Fail to update dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Interrupted when updating dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
    } finally {
        zkc.close();
    }
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 99 with KeeperException

use of org.apache.zookeeper.KeeperException in project bookkeeper by apache.

the class DLMetadata method unbind.

public static void unbind(URI uri) throws IOException {
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
    byte[] data = new byte[0];
    try {
        zkc.get().setData(uri.getPath(), data, -1);
    } catch (KeeperException ke) {
        throw new IOException("Fail to unbound dl metadata on uri " + uri, ke);
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new IOException("Interrupted when unbinding dl metadata on uri " + uri, ie);
    } finally {
        zkc.close();
    }
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 100 with KeeperException

use of org.apache.zookeeper.KeeperException in project bookkeeper by apache.

the class ZkMetadataResolver method resolve.

@Override
public DLMetadata resolve(URI uri) throws IOException {
    String dlPath = uri.getPath();
    PathUtils.validatePath(dlPath);
    // Normal case the dl metadata is stored in the last segment
    // so lookup last segment first.
    String[] parts = StringUtils.split(dlPath, '/');
    if (null == parts || 0 == parts.length) {
        throw new IOException("Invalid dlPath to resolve dl metadata : " + dlPath);
    }
    for (int i = parts.length; i >= 0; i--) {
        String pathToResolve = String.format("/%s", StringUtils.join(parts, '/', 0, i));
        byte[] data;
        try {
            data = zkc.get().getData(pathToResolve, false, new Stat());
        } catch (KeeperException.NoNodeException nne) {
            continue;
        } catch (KeeperException ke) {
            throw new IOException("Fail to resolve dl path : " + pathToResolve);
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
            throw new IOException("Interrupted when resolving dl path : " + pathToResolve);
        }
        if (null == data || data.length == 0) {
            continue;
        }
        try {
            return DLMetadata.deserialize(uri, data);
        } catch (IOException ie) {
            throw new IOException("Failed to deserialize uri : " + uri);
        }
    }
    throw new IOException("No bkdl config bound under dl path : " + dlPath);
}
Also used : Stat(org.apache.zookeeper.data.Stat) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

KeeperException (org.apache.zookeeper.KeeperException)566 IOException (java.io.IOException)188 Stat (org.apache.zookeeper.data.Stat)127 ZooKeeper (org.apache.zookeeper.ZooKeeper)87 ArrayList (java.util.ArrayList)51 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)45 Watcher (org.apache.zookeeper.Watcher)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 Test (org.junit.jupiter.api.Test)38 CountDownLatch (java.util.concurrent.CountDownLatch)30 SolrException (org.apache.solr.common.SolrException)30 HashMap (java.util.HashMap)29 List (java.util.List)28 ACL (org.apache.zookeeper.data.ACL)27 Test (org.junit.Test)27 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)25 ServerName (org.apache.hadoop.hbase.ServerName)24 Map (java.util.Map)23 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)23 InterruptedIOException (java.io.InterruptedIOException)20