use of com.ms.silverking.cloud.toporing.InstantiatedRingTree in project SilverKing by Morgan-Stanley.
the class RingInfo method readTree.
private InstantiatedRingTree readTree(Triple<String, Long, Long> ring) throws IOException, KeeperException {
MetaClient ringMC;
long ringConfigVersion;
long configInstanceVersion;
InstantiatedRingTree ringTree;
ringConfigVersion = ring.getTail().getV1();
configInstanceVersion = ring.getTail().getV2();
ringMC = metaUtil.getRingMC();
ringTree = SingleRingZK.readTree(ringMC, ringConfigVersion, configInstanceVersion);
return ringTree;
}
use of com.ms.silverking.cloud.toporing.InstantiatedRingTree in project SilverKing by Morgan-Stanley.
the class SKAdmin method getRing.
private static Pair<RingConfiguration, InstantiatedRingTree> getRing(DHTConfiguration dhtConfig, com.ms.silverking.cloud.dht.meta.MetaClient dhtMC) throws IOException, KeeperException {
String ringName;
Pair<Long, Long> ringVersion;
DHTRingCurTargetZK dhtRingCurTargetZK;
Triple<String, Long, Long> curRingNameAndVersion;
RingConfiguration ringConfig;
RingConfigurationZK ringConfigZK;
InstantiatedRingTree ringTree;
com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
curRingNameAndVersion = dhtRingCurTargetZK.getCurRingAndVersionPair();
if (curRingNameAndVersion == null) {
return null;
}
ringName = curRingNameAndVersion.getHead();
ringVersion = curRingNameAndVersion.getTail();
ringMC = com.ms.silverking.cloud.toporing.meta.MetaClient.createMetaClient(ringName, ringVersion.getV1(), dhtMC.getZooKeeper().getZKConfig());
ringConfigZK = new RingConfigurationZK(ringMC);
ringConfig = ringConfigZK.readFromZK(ringVersion.getV1(), null);
// ringTree = SingleRingZK.readTree(ringMC, ringVersion);
// FUTURE - think about whether or not we should keep this, currently unused
ringTree = null;
return new Pair<>(ringConfig, ringTree);
}
use of com.ms.silverking.cloud.toporing.InstantiatedRingTree 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.toporing.InstantiatedRingTree in project SilverKing by Morgan-Stanley.
the class HealthMonitor method dhtMetaUpdate.
@Override
public void dhtMetaUpdate(DHTMetaUpdate dhtMetaUpdate) {
Log.warning(String.format("Received dhtMetaUpdate %s", dhtMetaUpdate));
try {
InstantiatedRingTree rawRingTree;
ResolvedReplicaMap replicaMap;
instanceExclusionZK = new InstanceExclusionZK(dhtMetaUpdate.getMetaClient());
dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMetaUpdate.getMetaClient(), dhtMetaUpdate.getDHTConfig());
rawRingTree = dhtMetaUpdate.getRingTree();
replicaMap = rawRingTree.getResolvedMap(dhtMetaUpdate.getNamedRingConfiguration().getRingConfiguration().getRingParentName(), null);
activeNodesInMap = replicaMap.allReplicas();
synchronized (this) {
this.notifyAll();
}
} catch (Exception e) {
Log.logErrorWarning(e, "Exception in HealthMonitor.dhtMetaUpdate()");
}
}
use of com.ms.silverking.cloud.toporing.InstantiatedRingTree 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);
}
Aggregations