use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.
the class DHTMetaReader method readRing.
public DHTMetaUpdate readRing(String ringName, long ringConfigVersion, long configInstanceVersion) throws KeeperException, IOException {
com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
NamedRingConfiguration namedRingConfig;
RingConfiguration ringConfig;
InstantiatedRingTree ringTree;
// long ringConfigVersion;
// long configInstanceVersion;
int readAttemptIndex;
int ringReadAttempts = 20;
int ringReadRetryInvervalSeconds = 2;
ZooKeeperExtended zk;
zk = mc.getZooKeeper();
if (EmbeddedSK.embedded()) {
namedRingConfig = EmbeddedSK.getEmbeddedNamedRingConfiguration(ringName);
} else {
// unresolved
namedRingConfig = new NamedRingConfiguration(ringName, RingConfiguration.emptyTemplate);
ringMC = new com.ms.silverking.cloud.toporing.meta.MetaClient(namedRingConfig, zkConfig);
// ringConfigVersion = zk.getVersionPriorTo(ringMC.getMetaPaths().getConfigPath(), zkidLimit);
try {
ringConfig = new RingConfigurationZK(ringMC).readFromZK(ringConfigVersion, null);
} catch (Exception e) {
Log.warning("Ignoring: ", e);
ringConfig = new RingConfiguration(new CloudConfiguration(null, null, null), null, null, null, null, null);
}
// resolved
namedRingConfig = new NamedRingConfiguration(ringName, ringConfig);
if (enableLogging) {
Log.warning("ringConfig\t", ringConfig);
}
}
ringMC = new com.ms.silverking.cloud.toporing.meta.MetaClient(namedRingConfig, zkConfig);
// configInstanceVersion = zk.getVersionPriorTo(ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion), zkidLimit);
if (enableLogging) {
Log.warning("configInstanceVersion: " + configInstanceVersion);
}
if (configInstanceVersion < 0) {
throw new RuntimeException("Invalid configInstanceVersion: " + configInstanceVersion);
}
// if (configInstanceVersion == -1) {
// configInstanceVersion = 0;
// }
// FUTURE - we shouldn't get here unless it's valid. Think about error messages if invalid, instead of waiting.
Log.warning("Waiting until valid " + ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion) + " " + configInstanceVersion);
SingleRingZK.waitUntilValid(ringMC, ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion), configInstanceVersion);
Log.warning("Valid");
ringTree = null;
readAttemptIndex = 0;
while (ringTree == null) {
try {
// , weightsVersion);
ringTree = SingleRingZK.readTree(ringMC, ringConfigVersion, configInstanceVersion);
} catch (Exception e) {
if (++readAttemptIndex >= ringReadAttempts) {
throw new RuntimeException("Ring read failed", e);
} else {
ThreadUtil.sleepSeconds(ringReadRetryInvervalSeconds);
}
}
}
if (enableLogging) {
Log.warning("\t\t###\t" + ringConfigVersion + "\t" + configInstanceVersion);
}
return new DHTMetaUpdate(dhtConfig, namedRingConfig, ringTree, mc);
}
use of org.apache.flink.shaded.zookeeper3.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.flink.shaded.zookeeper3.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.flink.shaded.zookeeper3.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.flink.shaded.zookeeper3.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();
}
}
Aggregations