Search in sources :

Example 11 with ZooKeeperExtended

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;
    }
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) KeeperException(org.apache.zookeeper.KeeperException)

Example 12 with ZooKeeperExtended

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);
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 13 with ZooKeeperExtended

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()));
}
Also used : RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration)

Example 14 with ZooKeeperExtended

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)));
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 15 with ZooKeeperExtended

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;
}
Also used : IPAndPort(com.ms.silverking.net.IPAndPort) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) DaemonState(com.ms.silverking.cloud.dht.daemon.DaemonState)

Aggregations

ZooKeeperExtended (com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)33 KeeperException (org.apache.zookeeper.KeeperException)9 IOException (java.io.IOException)7 Stat (org.apache.zookeeper.data.Stat)4 NamedRingConfiguration (com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration)3 RingConfiguration (com.ms.silverking.cloud.toporing.meta.RingConfiguration)3 RingConfigurationZK (com.ms.silverking.cloud.toporing.meta.RingConfigurationZK)3 CmdLineException (org.kohsuke.args4j.CmdLineException)3 ExclusionSet (com.ms.silverking.cloud.meta.ExclusionSet)2 ServerSetExtensionZK (com.ms.silverking.cloud.meta.ServerSetExtensionZK)2 Topology (com.ms.silverking.cloud.topology.Topology)2 TopologyZK (com.ms.silverking.cloud.topology.TopologyZK)2 InstantiatedRingTree (com.ms.silverking.cloud.toporing.InstantiatedRingTree)2 ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)2 IPAndPort (com.ms.silverking.net.IPAndPort)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 OperationTimeoutException (org.apache.zookeeper.KeeperException.OperationTimeoutException)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HostGroupTable (com.ms.silverking.cloud.config.HostGroupTable)1