use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class VersionWatcher method _doCheck.
protected void _doCheck() throws KeeperException {
Log.fine("checkVersions");
try {
ZooKeeperExtended _zk;
List<String> children;
List<Long> currentVersions;
long mostRecentVersion;
if (verbose) {
Log.warning("VersionCheck start: ", basePath);
}
_zk = metaClientCore.getZooKeeper();
children = _zk.getChildren(basePath, this);
currentVersions = new ArrayList<>(children.size());
for (String child : children) {
currentVersions.add(Long.parseLong(child));
}
Collections.sort(currentVersions);
if (currentVersions.size() > 0) {
mostRecentVersion = currentVersions.get(currentVersions.size() - 1);
} else {
mostRecentVersion = Long.MIN_VALUE;
}
if (active && mostRecentVersion > lastNotifiedVersion) {
lastNotifiedVersion = mostRecentVersion;
listener.newVersion(basePath, mostRecentVersion);
}
if (verbose) {
Log.warning("VersionCheck complete: ", basePath);
}
} catch (KeeperException ke) {
System.out.println("*** ZooKeeper state: " + metaClientCore.getZooKeeper().getState());
throw ke;
}
}
use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class ChildrenWatcher method readChildStates.
private Map<String, byte[]> readChildStates() throws KeeperException {
ZooKeeperExtended _zk;
List<String> children;
_zk = metaClientCore.getZooKeeper();
children = _zk.getChildren(basePath, this);
return _zk.getByteArrays(basePath, ImmutableSet.copyOf(children), this, this);
}
use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class DHTMetaWatcher method readRing.
// FIXME - think about zkidLimit
public void readRing(String ringName, long zkidLimit) throws KeeperException, IOException {
com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
// com.ms.silverking.cloud.meta.MetaClient cloudMC;
NamedRingConfiguration namedRingConfig;
RingConfiguration ringConfig;
InstantiatedRingTree ringTree;
long ringConfigVersion;
long configInstanceVersion;
DHTMetaUpdate dhtMetaUpdate;
int readAttemptIndex;
int ringReadAttempts = 20;
int ringReadRetryInvervalSeconds = 2;
ZooKeeperExtended zk;
// cloudMC = new com.ms.silverking.cloud.meta.MetaClient(ringConfig.getCloudConfiguration(),
// zkConfig);
zk = mc.getZooKeeper();
// 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);
ringConfig = new RingConfigurationZK(ringMC).readFromZK(ringConfigVersion, null);
// resolved
namedRingConfig = new NamedRingConfiguration(ringName, ringConfig);
ringMC = new com.ms.silverking.cloud.toporing.meta.MetaClient(namedRingConfig, zkConfig);
if (enableLogging) {
Log.warning("ringConfig\t", ringConfig);
}
configInstanceVersion = zk.getVersionPriorTo(ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion), zkidLimit);
if (enableLogging) {
Log.warning("configInstanceVersion: " + configInstanceVersion);
}
if (configInstanceVersion == -1) {
configInstanceVersion = 0;
}
if (DHTConstants.isDaemon || Log.levelMet(Level.INFO)) {
Log.warning("Waiting until valid " + ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion) + " " + configInstanceVersion);
}
SingleRingZK.waitUntilValid(ringMC, ringMC.getMetaPaths().getConfigInstancePath(ringConfigVersion), configInstanceVersion);
if (DHTConstants.isDaemon || Log.levelMet(Level.INFO)) {
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);
}
dhtMetaUpdate = new DHTMetaUpdate(dhtConfig, namedRingConfig, ringTree, mc);
notifyListeners(dhtMetaUpdate);
// ringUpdateListener.newRingTree(new NamedRingConfiguration(ringName, ringConfig), ringTree);
// ringUpdateListener.newRingTree(ringTree.getMap(ringConfig.getRingParentName()));
}
use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class DaemonStateZK method readActiveNodesFromZK.
public Set<IPAndPort> readActiveNodesFromZK() throws KeeperException {
String basePath;
ZooKeeperExtended _zk;
basePath = mc.getMetaPaths().getInstanceDaemonStatePath();
_zk = mc.getZooKeeper();
return ImmutableSet.copyOf(IPAndPort.list(_zk.getChildren(basePath, this)));
}
use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class DaemonStateZK method _getQuorumState.
private Map<IPAndPort, DaemonState> _getQuorumState(Set<IPAndPort> members) throws KeeperException {
ZooKeeperExtended zk;
Set<String> daemonStatePaths;
Map<String, Integer> daemonStates;
Map<IPAndPort, DaemonState> quorumState;
daemonStatePaths = new HashSet<>(members.size());
for (IPAndPort member : members) {
daemonStatePaths.add(getMemberDaemonStatePath(member));
}
zk = mc.getZooKeeper();
daemonStates = zk.getInts(daemonStatePaths, this);
quorumState = new HashMap<>();
for (IPAndPort member : members) {
Integer rawState;
rawState = daemonStates.get(getMemberDaemonStatePath(member));
if (rawState != null) {
DaemonState ds;
ds = DaemonState.values()[rawState];
quorumState.put(member, ds);
}
}
return quorumState;
}
Aggregations