Search in sources :

Example 26 with ZooKeeperExtended

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

the class MetaClientCore method setZK.

private void setZK(ZooKeeperConfig zkConfig) throws IOException, KeeperException {
    Lock lock;
    ZooKeeperExtended _zk;
    lock = acquireLockIfShared(zkConfig);
    try {
        if (shareZK) {
            _zk = zkMap.get(zkConfig);
        } else {
            _zk = null;
        }
        if (_zk == null) {
            Log.info(String.format("Getting ZooKeeperExtended for %s\n", zkConfig));
            zk = ZooKeeperExtended.getZooKeeperWithRetries(zkConfig, sessionTimeout, this, connectAttempts);
            Log.info(String.format("Done getting ZooKeeperExtended for %s\n", zkConfig));
            if (shareZK) {
                zkMap.putIfAbsent(zkConfig, zk);
            }
        } else {
            zk = _zk;
        }
    } finally {
        releaseLockIfShared(lock);
    }
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 27 with ZooKeeperExtended

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

the class MetaClientCore method getZooKeeper.

public ZooKeeperExtended getZooKeeper(int getZKMaxAttempts, int getZKSleepUnit) throws KeeperException {
    ZooKeeperExtended _zk;
    int attemptIndex;
    assert getZKMaxAttempts > 0;
    assert getZKSleepUnit > 0;
    _zk = null;
    attemptIndex = 0;
    while (_zk == null) {
        _zk = _getZooKeeper();
        if (_zk == null) {
            if (attemptIndex < getZKMaxAttempts - 1) {
                ThreadUtil.randomSleep(getZKSleepUnit << attemptIndex);
                ++attemptIndex;
            } else {
                Log.warning("getZooKeeper() failed after " + (attemptIndex + 1) + " attempts");
                throw new OperationTimeoutException();
            }
        }
    }
    return _zk;
}
Also used : OperationTimeoutException(org.apache.zookeeper.KeeperException.OperationTimeoutException) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 28 with ZooKeeperExtended

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

the class NodeCreationWatcherTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        if (args.length < 2) {
            System.out.println("<zkConfig> <path...>");
        } else {
            ZooKeeperConfig zkConfig;
            NodeCreationWatcherTest wTest;
            zkConfig = new ZooKeeperConfig(args[0]);
            wTest = new NodeCreationWatcherTest(new ZooKeeperExtended(zkConfig, 2 * 60 * 1000, null));
            for (int i = 1; i < args.length; i++) {
                wTest.addWatch(args[i]);
            }
            Thread.sleep(60 * 60 * 1000);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 29 with ZooKeeperExtended

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

the class SuspectsZK method writeSuspectsToZK.

public void writeSuspectsToZK(IPAndPort accuser, Set<IPAndPort> suspects) throws IOException, KeeperException {
    String basePath;
    ZooKeeperExtended _zk;
    String path;
    basePath = mc.getMetaPaths().getInstanceSuspectsPath();
    _zk = mc.getZooKeeper();
    path = basePath + "/" + accuser;
    if (_zk.exists(path)) {
        _zk.setString(path, CollectionUtil.toString(suspects, suspectsDelimiter));
    } else {
        _zk.createString(path, CollectionUtil.toString(suspects, suspectsDelimiter), CreateMode.EPHEMERAL);
    }
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 30 with ZooKeeperExtended

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

the class SuspectsZK method readAccuserSuspectsFromZK.

/**
 * Read accuser->suspects map from zookeeper.
 * @return accuser->suspects map
 * @throws KeeperException
 */
public SetMultimap<IPAndPort, IPAndPort> readAccuserSuspectsFromZK() throws KeeperException {
    String basePath;
    List<IPAndPort> accusers;
    SetMultimap<IPAndPort, IPAndPort> accuserSuspectsMap;
    ZooKeeperExtended _zk;
    if (debug) {
        Log.warning("in readAccuserSuspectsFromZK()");
    }
    basePath = mc.getMetaPaths().getInstanceSuspectsPath();
    _zk = mc.getZooKeeper();
    accusers = IPAndPort.list(_zk.getChildren(basePath));
    accuserSuspectsMap = HashMultimap.create();
    for (IPAndPort accuser : accusers) {
        Set<IPAndPort> suspects;
        suspects = _readSuspectsFromZK(_zk, accuser);
        if (suspects != null) {
            accuserSuspectsMap.putAll(accuser, suspects);
        }
    }
    if (debug) {
        Log.warning("accuserSuspectsMap.size()\t", accuserSuspectsMap.size());
        Log.warning("out readAccuserSuspectsFromZK()");
    }
    return accuserSuspectsMap;
}
Also used : IPAndPort(com.ms.silverking.net.IPAndPort) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

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