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);
}
}
}
}
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();
}
}
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();
}
}
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();
}
}
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);
}
Aggregations