Search in sources :

Example 6 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class SingleRingZK method isValidRing.

// private static boolean isValidRing(MetaClient mc, String configInstancePath, String parentID, String policyName, long version) throws KeeperException {
// ZooKeeperExtended   zk;
// 
// zk = mc.getZooKeeper();
// return zk.getString(getBase(configInstancePath, parentID, policyName)).equals(validString);
// }
private static boolean isValidRing(MetaClient mc, String configInstancePath, String parentID, long version) throws KeeperException {
    ZooKeeperExtended zk;
    zk = mc.getZooKeeper();
    return zk.getString(getBase(configInstancePath, parentID)).equals(validString);
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 7 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class ExclusionZKBase method getStartOfCurrentExclusion.

public Map<String, Long> getStartOfCurrentExclusion(Set<String> servers) throws KeeperException {
    Map<String, Long> esStarts;
    long latestExclusionSetVersion;
    Map<String, Set<String>> exclusionSets;
    ZooKeeperExtended _zk;
    _zk = mc.getZooKeeper();
    esStarts = new HashMap<>();
    exclusionSets = new HashMap<>();
    latestExclusionSetVersion = _zk.getLatestVersion(exclusionsPath);
    for (String server : servers) {
        esStarts.put(server, getStartOfCurrentExclusion(server, latestExclusionSetVersion, exclusionSets));
    }
    return esStarts;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 8 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class MetaClientCore method handleSessionExpiration.

private void handleSessionExpiration() {
    Lock lock;
    lock = acquireLockIfShared(zkConfig);
    try {
        boolean established;
        established = false;
        while (!established) {
            ZooKeeperExtended _zk;
            ThreadUtil.sleepSeconds(connectionLossSleepSeconds);
            _zk = zkMap.get(zkConfig);
            if (_zk != null && _zk.getState() != States.CLOSED) {
                established = true;
            } else {
                zkMap.remove(zkConfig);
                try {
                    Log.warning(String.format("Attempting to reestablish session %s\n", zkConfig));
                    zk = ZooKeeperExtended.getZooKeeperWithRetries(zkConfig, sessionTimeout, this, connectAttempts);
                    Log.warning(String.format("Session restablished %s\n", zkConfig));
                    established = true;
                    if (shareZK) {
                        zkMap.put(zkConfig, zk);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    } finally {
        releaseLockIfShared(lock);
    }
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) OperationTimeoutException(org.apache.zookeeper.KeeperException.OperationTimeoutException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 9 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.

the class MetaClientCore method process.

@Override
public void process(WatchedEvent event) {
    ZooKeeperExtended _zk;
    _zk = _getZooKeeper();
    if (_zk == null || _zk.getState() == States.CLOSED) {
        handleSessionExpiration();
    }
    // Log.warning(event.toString());
    synchronized (this) {
        this.notifyAll();
    }
    if (watcher != null) {
        watcher.process(event);
    }
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 10 with ZooKeeperExtended

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

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