Search in sources :

Example 1 with InstantiatedRingTree

use of com.ms.silverking.cloud.toporing.InstantiatedRingTree in project SilverKing by Morgan-Stanley.

the class RingInfo method readTree.

private InstantiatedRingTree readTree(Triple<String, Long, Long> ring) throws IOException, KeeperException {
    MetaClient ringMC;
    long ringConfigVersion;
    long configInstanceVersion;
    InstantiatedRingTree ringTree;
    ringConfigVersion = ring.getTail().getV1();
    configInstanceVersion = ring.getTail().getV2();
    ringMC = metaUtil.getRingMC();
    ringTree = SingleRingZK.readTree(ringMC, ringConfigVersion, configInstanceVersion);
    return ringTree;
}
Also used : MetaClient(com.ms.silverking.cloud.toporing.meta.MetaClient) InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree)

Example 2 with InstantiatedRingTree

use of com.ms.silverking.cloud.toporing.InstantiatedRingTree in project SilverKing by Morgan-Stanley.

the class SKAdmin method getRing.

private static Pair<RingConfiguration, InstantiatedRingTree> getRing(DHTConfiguration dhtConfig, com.ms.silverking.cloud.dht.meta.MetaClient dhtMC) throws IOException, KeeperException {
    String ringName;
    Pair<Long, Long> ringVersion;
    DHTRingCurTargetZK dhtRingCurTargetZK;
    Triple<String, Long, Long> curRingNameAndVersion;
    RingConfiguration ringConfig;
    RingConfigurationZK ringConfigZK;
    InstantiatedRingTree ringTree;
    com.ms.silverking.cloud.toporing.meta.MetaClient ringMC;
    dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
    curRingNameAndVersion = dhtRingCurTargetZK.getCurRingAndVersionPair();
    if (curRingNameAndVersion == null) {
        return null;
    }
    ringName = curRingNameAndVersion.getHead();
    ringVersion = curRingNameAndVersion.getTail();
    ringMC = com.ms.silverking.cloud.toporing.meta.MetaClient.createMetaClient(ringName, ringVersion.getV1(), dhtMC.getZooKeeper().getZKConfig());
    ringConfigZK = new RingConfigurationZK(ringMC);
    ringConfig = ringConfigZK.readFromZK(ringVersion.getV1(), null);
    // ringTree = SingleRingZK.readTree(ringMC, ringVersion);
    // FUTURE - think about whether or not we should keep this, currently unused
    ringTree = null;
    return new Pair<>(ringConfig, ringTree);
}
Also used : RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree) DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) Pair(com.ms.silverking.collection.Pair)

Example 3 with InstantiatedRingTree

use of com.ms.silverking.cloud.toporing.InstantiatedRingTree 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 4 with InstantiatedRingTree

use of com.ms.silverking.cloud.toporing.InstantiatedRingTree in project SilverKing by Morgan-Stanley.

the class HealthMonitor method dhtMetaUpdate.

@Override
public void dhtMetaUpdate(DHTMetaUpdate dhtMetaUpdate) {
    Log.warning(String.format("Received dhtMetaUpdate %s", dhtMetaUpdate));
    try {
        InstantiatedRingTree rawRingTree;
        ResolvedReplicaMap replicaMap;
        instanceExclusionZK = new InstanceExclusionZK(dhtMetaUpdate.getMetaClient());
        dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMetaUpdate.getMetaClient(), dhtMetaUpdate.getDHTConfig());
        rawRingTree = dhtMetaUpdate.getRingTree();
        replicaMap = rawRingTree.getResolvedMap(dhtMetaUpdate.getNamedRingConfiguration().getRingConfiguration().getRingParentName(), null);
        activeNodesInMap = replicaMap.allReplicas();
        synchronized (this) {
            this.notifyAll();
        }
    } catch (Exception e) {
        Log.logErrorWarning(e, "Exception in HealthMonitor.dhtMetaUpdate()");
    }
}
Also used : InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree) ResolvedReplicaMap(com.ms.silverking.cloud.toporing.ResolvedReplicaMap) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 5 with InstantiatedRingTree

use of com.ms.silverking.cloud.toporing.InstantiatedRingTree 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)

Aggregations

InstantiatedRingTree (com.ms.silverking.cloud.toporing.InstantiatedRingTree)10 NamedRingConfiguration (com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration)5 RingConfiguration (com.ms.silverking.cloud.toporing.meta.RingConfiguration)4 MetaClient (com.ms.silverking.cloud.toporing.meta.MetaClient)3 RingConfigurationZK (com.ms.silverking.cloud.toporing.meta.RingConfigurationZK)3 IOException (java.io.IOException)3 KeeperException (org.apache.zookeeper.KeeperException)3 DHTRingCurTargetZK (com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK)2 ResolvedReplicaMap (com.ms.silverking.cloud.toporing.ResolvedReplicaMap)2 ZooKeeperExtended (com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 HostGroupTable (com.ms.silverking.cloud.config.HostGroupTable)1 ReplicaNaiveIPPrioritizer (com.ms.silverking.cloud.dht.daemon.ReplicaNaiveIPPrioritizer)1 CloudConfiguration (com.ms.silverking.cloud.meta.CloudConfiguration)1 ExclusionSet (com.ms.silverking.cloud.meta.ExclusionSet)1 SKFSNamespaceCreator (com.ms.silverking.cloud.skfs.management.SKFSNamespaceCreator)1 Pair (com.ms.silverking.collection.Pair)1 IPAndPort (com.ms.silverking.net.IPAndPort)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1