use of org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.
the class StaticRingCreator method createStaticRing.
public static RingCreationResults createStaticRing(String ringName, ZooKeeperConfig zkConfig, Set<String> servers, int replication, UUIDBase myID) {
try {
MetaClient mc;
com.ms.silverking.cloud.meta.MetaClient cloudMC;
NamedRingConfiguration namedRingConfig;
RingConfiguration ringConfig;
RingTreeRecipe recipe;
Topology topology;
WeightSpecifications weightSpecs;
ExclusionSet exclusionSet;
StoragePolicyGroup storagePolicyGroup;
HostGroupTable hostGroupTable;
long ringConfigVersion;
CloudConfiguration cloudConfig;
String exclusionSpecsName;
String hostGroupTableName;
topology = StaticTopologyCreator.createTopology("topology." + myID, servers);
exclusionSpecsName = "exclusionSpecs." + myID;
hostGroupTableName = "hostGroupTable." + myID;
cloudConfig = new CloudConfiguration(topology.getName(), exclusionSpecsName, hostGroupTableName);
cloudMC = new com.ms.silverking.cloud.meta.MetaClient(cloudConfig, zkConfig);
new TopologyZK(cloudMC).writeToZK(topology, null);
new ExclusionZK(cloudMC).writeToZK(ExclusionSet.emptyExclusionSet(0));
mc = new MetaClient(NamedRingConfiguration.emptyTemplate.ringName(ringName), zkConfig);
ringConfig = new RingConfiguration(cloudConfig, "weightSpecsName", StaticTopologyCreator.parentID, SimpleStoragePolicyCreator.storagePolicyGroupName, SimpleStoragePolicyCreator.storagePolicyName, null);
new RingConfigurationZK(mc).writeToZK(ringConfig, null);
namedRingConfig = new NamedRingConfiguration(ringName, ringConfig);
mc = new MetaClient(namedRingConfig, zkConfig);
EmbeddedSK.setEmbeddedNamedRingConfiguration(ringName, namedRingConfig);
Log.warning(zkConfig);
ringConfigVersion = 0;
weightSpecs = new WeightSpecifications(0);
exclusionSet = ExclusionSet.emptyExclusionSet(0);
storagePolicyGroup = SimpleStoragePolicyCreator.createStoragePolicyGroup(replication);
new StoragePolicyZK(mc).writeToZK(storagePolicyGroup, null);
hostGroupTable = HostGroupTable.createHostGroupTable(servers, hostGroupName);
new HostGroupTableZK(cloudMC).writeToZK(hostGroupTable, null);
recipe = new RingTreeRecipe(topology, StaticTopologyCreator.parentID, weightSpecs, exclusionSet, storagePolicyGroup, SimpleStoragePolicyCreator.storagePolicyName, hostGroupTable, ImmutableSet.of(hostGroupName), ringConfigVersion, DHTUtil.currentTimeMillis());
Log.warning("Recipe.ringParent: " + recipe.ringParent);
RingTree ringTree;
String newInstancePath;
ringTree = RingTreeBuilder.create(recipe, null);
newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
SingleRingZK.writeTree(mc, topology, newInstancePath, ringTree);
if (TopoRingConstants.verbose) {
System.out.println(ringTree);
System.out.println("Building complete");
}
return new RingCreationResults(exclusionSpecsName, hostGroupTableName, hostGroupTable, hostGroupName);
} catch (IOException ioe) {
Log.logErrorWarning(ioe);
return null;
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
return null;
}
}
use of org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.
the class ValueWatcher method _doCheck.
protected void _doCheck() throws KeeperException {
try {
ZooKeeperExtended _zk;
byte[] value;
Stat stat;
if (verbose) {
Log.warning("ValueCheck start: ", basePath);
}
_zk = metaClientCore.getZooKeeper();
stat = new Stat();
try {
value = _zk.getData(basePath, this, stat);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (stat.getMzxid() > lastNotifiedZXID) {
listener.newValue(basePath, value, stat);
lastNotifiedZXID = stat.getMzxid();
}
if (verbose) {
Log.warning("ValueCheck complete: ", basePath);
}
} catch (KeeperException ke) {
System.out.println("*** ZooKeeper state: " + metaClientCore.getZooKeeper().getState());
throw ke;
}
}
use of org.apache.zookeeper.KeeperException 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 org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.
the class DHTRingMaster method syncData.
public void syncData(Quadruple<UUIDBase, Quadruple<String, Long, Long, Long>, Quadruple<String, Long, Long, Long>, SyncTargets> idAndRings) {
UUIDBase uuid;
Quadruple<String, Long, Long, Long> sourceRing;
Quadruple<String, Long, Long, Long> targetRing;
uuid = idAndRings.getV1();
sourceRing = idAndRings.getV2();
targetRing = idAndRings.getV3();
Log.warningAsyncf("DHTRingMaster.syncData %s %s %s", uuid, sourceRing.getV1(), targetRing.getV1());
convergenceLock.lock();
try {
if (/*!isValidTarget(targetRing)*/
false) {
// FUTURE think about checking validity
// FUTURE - could improve this sanity check to look at zk info
Log.warningAsyncf("Ignoring invalid sync %s %s", sourceRing, targetRing);
} else {
if (enableLogging) {
Log.warningAsync("New ring: ", targetRing);
}
try {
ConvergencePoint _sourceCP;
ConvergencePoint _targetCP;
// Check for old convergence
if (targetConvergenceController != null) {
if (enableLogging) {
Log.warningAsync("Can't sync due to ongoing convergence: ", targetRing);
return;
}
}
// Start new sync
_sourceCP = new ConvergencePoint(dhtConfig.getVersion(), RingIDAndVersionPair.fromRingNameAndVersionPair(sourceRing.getTripleAt1()), sourceRing.getV4());
_targetCP = new ConvergencePoint(dhtConfig.getVersion(), RingIDAndVersionPair.fromRingNameAndVersionPair(targetRing.getTripleAt1()), targetRing.getV4());
try {
targetConvergenceController = new CentralConvergenceController(uuid, dhtMetaReader, _sourceCP, _targetCP, readExclusions(targetRing), mgBase, syncUnchangedOwners, CentralConvergenceController.RequestedSyncMode.SyncOnly);
convergenceControllers.put(targetConvergenceController.getUUID(), targetConvergenceController);
} catch (IOException ioe) {
Log.logErrorWarning(ioe, "Unable to start sync");
return;
}
try {
convergenceLock.unlock();
try {
if (enableLogging) {
Log.warningAsync("Calling converge(): ", targetRing);
}
((CentralConvergenceController) targetConvergenceController).converge(idAndRings.getV4());
} finally {
convergenceLock.lock();
}
targetConvergenceController = null;
if (enableLogging) {
Log.warningAsync("Convergence complete: ", targetRing);
}
} catch (ConvergenceException ce) {
// Convergence failed
if (!ce.getAbandoned()) {
// Failed due to an exception
Log.logErrorWarning(ce, "Convergence failed due to exception");
} else {
// Failed due to a new target causing the old convergence to be abandoned
// In this case, the new convergence will take over the cur and target pointers
Log.warningAsync("Previous convergence abandoned");
}
}
} catch (KeeperException ke) {
// Retries are internal to DHTringCurTargetZK. If we got here, those
// retries failed.
// FUTURE - relay to alerting
Log.logErrorWarning(ke, "Unexpected exception during peerStateMet handling");
}
}
} finally {
convergenceLock.unlock();
}
}
use of org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.
the class SystemNamespaceStore method getAllReplicasFreeSystemDiskBytesEstimate.
private byte[] getAllReplicasFreeSystemDiskBytesEstimate() {
List<Pair<IPAndPort, Long>> results;
Map<IPAndPort, NodeInfo> nodeInfo;
results = new ArrayList<>();
try {
nodeInfo = getAllNodeInfo();
for (IPAndPort node : ringMaster.getAllCurrentReplicaServers()) {
NodeInfo info;
info = nodeInfo.get(node);
if (info != null) {
long freeSystemBytesEstimate;
freeSystemBytesEstimate = (long) ((double) info.getFSFreeBytes() / ringMaster.getCurrentOwnedFraction(node, OwnerQueryMode.Primary));
results.add(new Pair<>(node, freeSystemBytesEstimate));
}
}
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
}
return pairedResultsToBytes(results);
}
Aggregations