use of com.ms.silverking.cloud.meta.ServerSetExtensionZK in project SilverKing by Morgan-Stanley.
the class DependencyWatcher method build.
private void build(Map<String, Long> curBuild) {
try {
boolean buildOK;
long ringConfigVersion;
Log.warning("New build triggered");
buildOK = false;
ringConfigVersion = -1;
try {
if (TopoRingConstants.verbose) {
System.out.println("Building tree");
}
RingTreeRecipe recipe;
Topology topology;
WeightSpecifications weightSpecs;
ExclusionSet exclusionSet;
ExclusionSet instanceExclusionSet;
StoragePolicyGroup storagePolicyGroup;
long topologyVersion;
long weightsVersion;
long exclusionVersion;
long instanceExclusionVersion;
long storagePolicyGroupVersion;
RingConfiguration ringConfig;
ZooKeeperExtended zk;
HostGroupTable hostGroupTable;
long hostGroupTableVersion;
ExclusionSet mergedExclusionSet;
zk = mc.getZooKeeper();
topologyVersion = curBuild.get(mp.getTopologyPath());
weightsVersion = curBuild.get(mp.getWeightsPath());
exclusionVersion = curBuild.get(mp.getExclusionsPath());
instanceExclusionVersion = curBuild.get(dhtMC.getMetaPaths().getInstanceExclusionsPath());
storagePolicyGroupVersion = curBuild.get(mp.getStoragePolicyGroupPath());
ringConfigVersion = curBuild.get(mp.getConfigPath());
topology = new TopologyZK(cloudMC).readFromZK(topologyVersion, null);
weightSpecs = new WeightsZK(mc).readFromZK(weightsVersion, null);
exclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, mc.getMetaPaths().getExclusionsPath()).readFromZK(exclusionVersion, null));
if (options.ignoreInstanceExclusions) {
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
} else {
try {
instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readFromZK(instanceExclusionVersion, null));
} catch (Exception e) {
Log.warning("No instance ExclusionSet found");
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
}
}
mergedExclusionSet = ExclusionSet.union(exclusionSet, instanceExclusionSet);
storagePolicyGroup = new StoragePolicyGroupZK(mc).readFromZK(storagePolicyGroupVersion, null);
ringConfig = new RingConfigurationZK(mc).readFromZK(ringConfigVersion, null);
Log.warningf("ringConfiguration %s", ringConfig);
hostGroupTableVersion = zk.getLatestVersion(cloudMC.getMetaPaths().getHostGroupPath());
hostGroupTable = new HostGroupTableZK(cloudMC).readFromZK(hostGroupTableVersion, null);
try {
recipe = new RingTreeRecipe(topology, ringConfig.getRingParentName(), weightSpecs, mergedExclusionSet, storagePolicyGroup, ringConfig.getStoragePolicyName(), hostGroupTable, ringConfig.getHostGroups(), ringConfigVersion, DHTUtil.currentTimeMillis());
Log.warning("Recipe.ringParent: " + recipe.ringParent);
} catch (RuntimeException re) {
re.printStackTrace(System.out);
Log.warning("ringConfig: ", ringConfig + " " + re);
Log.logErrorWarning(re);
throw re;
}
RingTree ringTree;
RingTree prevRingTree;
long configInstanceVersion;
String newInstancePath;
configInstanceVersion = mc.getLatestConfigInstanceVersion(ringConfigVersion);
if (configInstanceVersion >= 0 && !ignoreSource) {
prevRingTree = SingleRingZK.readTree(mc, ringConfigVersion, configInstanceVersion);
} else {
prevRingTree = null;
}
if (prevRingTree == null || ignoreFeasibility || RingTreeBuilder.convergenceFeasible(prevRingTree, storagePolicyGroup, ringConfig.getStoragePolicyName(), ringConfig.getRingParentName(), exclusionSet)) {
ringTree = RingTreeBuilder.create(recipe, prevRingTree);
// ringTree = RingTreeBuilder.create(recipe, null); // for testing without movement reduction
newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
SingleRingZK.writeTree(mc, topologyVersion, newInstancePath, ringTree);
if (TopoRingConstants.verbose) {
System.out.println(ringTree);
System.out.println(ringConfigVersion);
System.out.println(configInstanceVersion);
System.out.println(topologyVersion);
System.out.println(newInstancePath);
System.out.println("Building complete");
}
buildOK = true;
} else {
Log.warning("Convergence is infeasible. A region in prevTree does not have a viable server.");
}
} catch (IOException ioe) {
Log.logErrorWarning(ioe);
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
}
if (exitAfterBuild) {
if (buildOK) {
try {
if (ringConfigVersion < 0) {
throw new RuntimeException("ringConfigVersion < 0");
}
setRing(ringConfigVersion);
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
buildOK = false;
}
}
System.exit(buildOK ? 0 : -1);
}
} catch (RuntimeException re) {
re.printStackTrace();
} finally {
Log.warning("Leaving build");
}
}
use of com.ms.silverking.cloud.meta.ServerSetExtensionZK in project SilverKing by Morgan-Stanley.
the class MasterModeDependencyWatcher method handleExclusionChange.
private void handleExclusionChange() {
synchronized (this) {
try {
Map<String, Long> curBuild;
ExclusionSet exclusionSet;
ExclusionSet instanceExclusionSet;
long exclusionVersion;
long instanceExclusionVersion;
ZooKeeperExtended zk;
ExclusionSet mergedExclusionSet;
RingTree existingRingTree;
RingTree newRingTree;
String newInstancePath;
ResolvedReplicaMap newReplicaMap;
zk = mc.getZooKeeper();
curBuild = createBuildMap(zk);
exclusionVersion = curBuild.get(mp.getExclusionsPath());
instanceExclusionVersion = curBuild.get(dhtMC.getMetaPaths().getInstanceExclusionsPath());
exclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, mc.getMetaPaths().getExclusionsPath()).readFromZK(exclusionVersion, null));
try {
instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readFromZK(instanceExclusionVersion, null));
} catch (Exception e) {
Log.warning("No instance ExclusionSet found");
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
}
mergedExclusionSet = ExclusionSet.union(exclusionSet, instanceExclusionSet);
newRingTree = RingTreeBuilder.removeExcludedNodes(masterRingTree, mergedExclusionSet);
newReplicaMap = newRingTree.getResolvedMap(ringConfig.getRingConfiguration().getRingParentName(), new ReplicaNaiveIPPrioritizer());
if (!existingReplicaMap.equals(newReplicaMap)) {
newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
SingleRingZK.writeTree(mc, topology, newInstancePath, newRingTree);
Log.warningf("RingTree written to ZK: %s", newInstancePath);
existingReplicaMap = newReplicaMap;
} else {
Log.warning("RingTree unchanged. No ZK update.");
}
} catch (Exception e) {
e.printStackTrace();
Log.logErrorWarning(e, "handleExclusionChange() failed");
}
}
}
use of com.ms.silverking.cloud.meta.ServerSetExtensionZK in project SilverKing by Morgan-Stanley.
the class DHTRingMaster method readExclusions.
private ExclusionSet readExclusions(String ringName, long ringVersion) throws KeeperException, IOException {
ExclusionZK exclusionZK;
ExclusionSet instanceExclusionSet;
ExclusionSet exclusionSet;
com.ms.silverking.cloud.meta.MetaClient cloudMC;
com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
ringMC = com.ms.silverking.cloud.toporing.meta.MetaClient.createMetaClient(ringName, ringVersion, zkConfig);
cloudMC = ringMC.createCloudMC();
exclusionZK = new ExclusionZK(cloudMC);
try {
exclusionSet = exclusionZK.readLatestFromZK();
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warningAsync("No ExclusionSet found. Using empty set.");
exclusionSet = ExclusionSet.emptyExclusionSet(0);
}
try {
instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, mc.getMetaPaths().getInstanceExclusionsPath()).readLatestFromZK());
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warningAsync("No instance ExclusionSet found. Using empty set.");
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
}
return ExclusionSet.union(exclusionSet, instanceExclusionSet);
}
use of com.ms.silverking.cloud.meta.ServerSetExtensionZK in project SilverKing by Morgan-Stanley.
the class RingMapState method readInitialExclusions.
/*
private void waitForExclusionSet() {
Log.warningf("waitForExclusionSet: %s", ringIDAndVersionPair);
exclusionSetLock.lock();
try {
while (!exclusionSetInitialized) {
try {
exclusionSetCV.await();
} catch (InterruptedException e) {
}
}
} finally {
exclusionSetLock.unlock();
}
Log.warningf("out waitForExclusionSet: %s", ringIDAndVersionPair);
}
*/
private void readInitialExclusions(MetaClient mc) throws KeeperException {
ExclusionZK exclusionZK;
ExclusionSet instanceExclusionSet;
ExclusionSet exclusionSet;
RingTree newRingTree;
ResolvedReplicaMap newResolvedReplicaMap;
Log.warning("RingMapState reading initial exclusions");
exclusionZK = new ExclusionZK(mc);
try {
exclusionSet = exclusionZK.readLatestFromZK();
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warning("No ExclusionSet found. Using empty set.");
exclusionSet = ExclusionSet.emptyExclusionSet(0);
}
curExclusionSet = exclusionSet;
Log.warning("curExclusionSet initialized:\n", curExclusionSet);
try {
instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(dhtMC, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readLatestFromZK());
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warning("No instance ExclusionSet found. Using empty set.");
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
}
curInstanceExclusionSet = instanceExclusionSet;
Log.warning("curInstanceExclusionSet initialized:\n", curInstanceExclusionSet);
try {
newRingTree = RingTreeBuilder.removeExcludedNodes(rawRingTree, ExclusionSet.union(curExclusionSet, curInstanceExclusionSet));
} catch (Exception e) {
Log.logErrorWarning(e);
throw new RuntimeException(e);
}
newResolvedReplicaMap = newRingTree.getResolvedMap(ringConfig.getRingParentName(), new ReplicaNaiveIPPrioritizer());
ringTreeMinusExclusions = newRingTree;
resolvedReplicaMapMinusExclusions = newResolvedReplicaMap;
System.out.println("\tResolved Map");
resolvedReplicaMapMinusExclusions.display();
Log.warning("RingMapState done reading initial exclusions");
}
use of com.ms.silverking.cloud.meta.ServerSetExtensionZK in project SilverKing by Morgan-Stanley.
the class RingMapState2 method readInitialExclusions.
private void readInitialExclusions(MetaClient mc) throws KeeperException {
ExclusionZK exclusionZK;
ExclusionSet instanceExclusionSet;
ExclusionSet exclusionSet;
RingTree newRingTree;
ResolvedReplicaMap newResolvedReplicaMap;
Log.warning("RingMapState reading initial exclusions");
exclusionZK = new ExclusionZK(mc);
try {
exclusionSet = exclusionZK.readLatestFromZK();
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warning("No ExclusionSet found. Using empty set.");
exclusionSet = ExclusionSet.emptyExclusionSet(0);
}
curExclusionSet = exclusionSet;
Log.warning("curExclusionSet initialized:\n", curExclusionSet);
try {
instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(dhtMC, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readLatestFromZK());
} catch (Exception e) {
Log.logErrorWarning(e);
Log.warning("No instance ExclusionSet found. Using empty set.");
instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
}
curInstanceExclusionSet = instanceExclusionSet;
Log.warning("curInstanceExclusionSet initialized:\n", curInstanceExclusionSet);
curUnionExclusionSet = ExclusionSet.union(curExclusionSet, curInstanceExclusionSet);
Log.warningf("curUnionExclusionSet initialized: %s", curUnionExclusionSet);
try {
newRingTree = RingTreeBuilder.removeExcludedNodes(rawRingTree, curUnionExclusionSet);
} catch (Exception e) {
Log.logErrorWarning(e);
throw new RuntimeException(e);
}
newResolvedReplicaMap = newRingTree.getResolvedMap(ringConfig.getRingParentName(), new SimpleIPDistancePrioritizer(nodeID, defaultIPDistanceMask));
ringTreeMinusExclusions = newRingTree;
resolvedReplicaMapMinusExclusions = newResolvedReplicaMap;
if (Log.levelMet(Level.INFO)) {
System.out.println("\tResolved Map");
resolvedReplicaMapMinusExclusions.display();
}
Log.warning("RingMapState done reading initial exclusions");
}
Aggregations