Search in sources :

Example 16 with ZooKeeperExtended

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

the class SuspectsZK method clearAllZK.

public void clearAllZK() throws IOException, KeeperException {
    String basePath;
    ZooKeeperExtended _zk;
    basePath = mc.getMetaPaths().getInstanceSuspectsPath();
    _zk = mc.getZooKeeper();
    for (String child : zk.getChildren(basePath)) {
        _zk.delete(basePath + "/" + child);
    }
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 17 with ZooKeeperExtended

use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended 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);
}
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) CloudConfiguration(com.ms.silverking.cloud.meta.CloudConfiguration)

Example 18 with ZooKeeperExtended

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

the class ExclusionZKBase method writeToZK.

@Override
public String writeToZK(ExclusionSet exclusionSet, MetaToolOptions options) throws IOException, KeeperException {
    String vBase;
    String zkVal;
    ZooKeeperExtended _zk;
    _zk = mc.getZooKeeper();
    zkVal = CollectionUtil.toString(exclusionSet.getServers(), "", "", delimiterChar, "");
    vBase = _zk.createString(base + "/", zkVal, CreateMode.PERSISTENT_SEQUENTIAL);
    /*
        vBase = zk.createString(base +"/" , "", CreateMode.PERSISTENT_SEQUENTIAL);
        for (String entity : exclusionList.getServers()) {
            //System.out.println(vBase +"/"+ entity);
            zk.createString(vBase +"/"+ entity, entity);
        }
        */
    return null;
}
Also used : ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 19 with ZooKeeperExtended

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

the class ExclusionZKBase method getVersionMzxid.

public long getVersionMzxid(long version) throws KeeperException {
    Stat stat;
    ZooKeeperExtended _zk;
    _zk = mc.getZooKeeper();
    stat = new Stat();
    _zk.getString(getVBase(version), null, stat);
    return stat.getMzxid();
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Example 20 with ZooKeeperExtended

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

the class ExclusionZKBase method readLatestFromZK.

public ExclusionSet readLatestFromZK(MetaToolOptions options) throws KeeperException {
    String vBase;
    long version;
    Stat stat;
    ZooKeeperExtended _zk;
    _zk = mc.getZooKeeper();
    version = _zk.getLatestVersion(exclusionsPath);
    if (version >= 0) {
        vBase = getVBase(version);
        stat = new Stat();
        return new ExclusionSet(readNodesAsSet(vBase, stat), version, stat.getMzxid());
    } else {
        return ExclusionSet.emptyExclusionSet(0);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) 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