use of org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.
the class SystemNamespaceStore method getAllReplicasFreeDiskBytes.
private byte[] getAllReplicasFreeDiskBytes() {
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) {
results.add(new Pair<>(node, info.getFSFreeBytes()));
}
}
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
}
return pairedResultsToBytes(results);
}
use of org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.
the class SKAdmin method _getActiveDaemons.
private Pair<Boolean, Set<IPAndPort>> _getActiveDaemons() {
try {
Set<IPAndPort> activeDaemons;
activeDaemons = suspectsZK.readActiveNodesFromZK();
for (IPAndPort daemon : activeDaemons) {
System.out.printf("%s\n", daemon.getIPAsString());
}
return new Pair<>(true, activeDaemons);
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
return new Pair(false, ImmutableSet.of());
}
}
use of org.apache.zookeeper.KeeperException 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 org.apache.zookeeper.KeeperException in project SilverKing by Morgan-Stanley.
the class DaemonStateZK method waitForQuorumState.
public Map<IPAndPort, DaemonState> waitForQuorumState(Set<IPAndPort> members, DaemonState targetState, int inactiveNodeTimeoutSeconds, boolean exitOnTimeout) {
boolean targetReached;
int lastNotReadyCount;
int notReadyCount;
int inactiveCount;
Stopwatch sw;
Set<IPAndPort> incompleteMembers;
incompleteMembers = new HashSet<>(members);
if (verbose) {
System.out.printf("Waiting for quorum state: %s\n", targetState);
}
sw = new SimpleStopwatch();
lastNotReadyCount = Integer.MAX_VALUE;
targetReached = false;
randomAwait(0, minQuorumStatePollIntervalMillis);
while (!targetReached) {
StringBuilder sb;
sb = new StringBuilder();
try {
if (mc.getZooKeeper().getState() == States.CONNECTED) {
Map<IPAndPort, DaemonState> quorumState;
Stopwatch qsSW;
Set<IPAndPort> newlyCompleteMembers;
Pair<Boolean, Map<IPAndPort, DaemonState>> rVal;
boolean allRead;
qsSW = new SimpleStopwatch();
rVal = getQuorumState(incompleteMembers, targetState);
qsSW.stop();
Log.info("getQuorumState elapsed ", qsSW.getElapsedSeconds());
allRead = rVal.getV1();
quorumState = rVal.getV2();
targetReached = true;
notReadyCount = 0;
inactiveCount = 0;
newlyCompleteMembers = new HashSet<>();
for (IPAndPort incompleteMember : incompleteMembers) {
DaemonState memberState;
memberState = quorumState.get(incompleteMember);
if (verbose && allRead) {
sb.append(String.format("%s\t%s\n", incompleteMember, memberState));
}
if (memberState == null) {
if (allRead) {
++inactiveCount;
if ((int) sw.getSplitSeconds() < inactiveNodeTimeoutSeconds) {
++notReadyCount;
targetReached = false;
} else {
sb.append(String.format("%s\t%s\tinactive node timed out\n", incompleteMember, memberState));
if (exitOnTimeout) {
Map<IPAndPort, DaemonState> stateMap;
System.out.print(sb);
Log.warningf("Timeout: %s", incompleteMember);
stateMap = fetchAndDisplayIncompleteState(incompleteMembers, targetState);
return stateMap;
}
}
} else {
targetReached = false;
}
} else if (memberState.ordinal() < targetState.ordinal()) {
targetReached = false;
++notReadyCount;
} else {
newlyCompleteMembers.add(incompleteMember);
}
}
incompleteMembers.removeAll(newlyCompleteMembers);
if (verbose) {
if (allRead) {
if (notReadyCount != lastNotReadyCount) {
System.out.print(sb);
} else {
System.out.printf("Waiting for %d nodes\n", notReadyCount);
}
} else {
System.out.printf("waitForQuorumState > %d incomplete\n", maxIncompletePerFetch);
}
}
lastNotReadyCount = notReadyCount;
}
} catch (KeeperException ke) {
Log.logErrorWarning(ke);
}
if (!targetReached) {
int maxSleepMillis;
if ((int) sw.getSplitSeconds() > inactiveNodeTimeoutSeconds) {
if (exitOnTimeout) {
Map<IPAndPort, DaemonState> stateMap;
Log.warningf("Timeout in targetState: %s", targetState);
try {
stateMap = fetchAndDisplayIncompleteState(incompleteMembers, targetState);
} catch (KeeperException e) {
e.printStackTrace();
stateMap = ImmutableMap.of();
}
return stateMap;
}
}
maxSleepMillis = (int) Math.max((double) maxQuorumStatePollIntervalMillis * ((double) incompleteMembers.size() / (double) maxQuorumStatePollThreshold), minQuorumStatePollIntervalMillis);
maxSleepMillis = Math.min(maxSleepMillis, maxQuorumStatePollIntervalMillis);
Log.info("waitForQuorumState maxSleepMillis: ", maxSleepMillis);
expectedSignals = incompleteMembers.size();
randomAwait(minQuorumStatePollIntervalMillis, maxSleepMillis);
Log.info("waitForQuorumState awake");
}
}
if (verbose) {
System.out.printf("Quorum state reached: %s\n", targetState);
}
return ImmutableMap.of();
}
use of 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);
}
Aggregations