Search in sources :

Example 1 with ReplicaNaiveIPPrioritizer

use of com.ms.silverking.cloud.dht.daemon.ReplicaNaiveIPPrioritizer in project SilverKing by Morgan-Stanley.

the class MasterModeDependencyWatcher method handleExclusionChange.

private void handleExclusionChange() {
    synchronized (this) {
        try {
            Map<String, Long> curBuild;
            ExclusionSet exclusionSet;
            ExclusionSet instanceExclusionSet;
            long exclusionVersion;
            long instanceExclusionVersion;
            ZooKeeperExtended zk;
            ExclusionSet mergedExclusionSet;
            RingTree existingRingTree;
            RingTree newRingTree;
            String newInstancePath;
            ResolvedReplicaMap newReplicaMap;
            zk = mc.getZooKeeper();
            curBuild = createBuildMap(zk);
            exclusionVersion = curBuild.get(mp.getExclusionsPath());
            instanceExclusionVersion = curBuild.get(dhtMC.getMetaPaths().getInstanceExclusionsPath());
            exclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, mc.getMetaPaths().getExclusionsPath()).readFromZK(exclusionVersion, null));
            try {
                instanceExclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, dhtMC.getMetaPaths().getInstanceExclusionsPath()).readFromZK(instanceExclusionVersion, null));
            } catch (Exception e) {
                Log.warning("No instance ExclusionSet found");
                instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
            }
            mergedExclusionSet = ExclusionSet.union(exclusionSet, instanceExclusionSet);
            newRingTree = RingTreeBuilder.removeExcludedNodes(masterRingTree, mergedExclusionSet);
            newReplicaMap = newRingTree.getResolvedMap(ringConfig.getRingConfiguration().getRingParentName(), new ReplicaNaiveIPPrioritizer());
            if (!existingReplicaMap.equals(newReplicaMap)) {
                newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
                SingleRingZK.writeTree(mc, topology, newInstancePath, newRingTree);
                Log.warningf("RingTree written to ZK: %s", newInstancePath);
                existingReplicaMap = newReplicaMap;
            } else {
                Log.warning("RingTree unchanged. No ZK update.");
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.logErrorWarning(e, "handleExclusionChange() failed");
        }
    }
}
Also used : ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) ReplicaNaiveIPPrioritizer(com.ms.silverking.cloud.dht.daemon.ReplicaNaiveIPPrioritizer) ServerSetExtensionZK(com.ms.silverking.cloud.meta.ServerSetExtensionZK) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 2 with ReplicaNaiveIPPrioritizer

use of com.ms.silverking.cloud.dht.daemon.ReplicaNaiveIPPrioritizer in project SilverKing by Morgan-Stanley.

the class SKAdmin method replicaSetExcludedByExclusions.

private boolean replicaSetExcludedByExclusions(ExclusionSet es) throws KeeperException, IOException {
    InstantiatedRingTree curTree;
    ResolvedReplicaMap replicaMap;
    List<Set<IPAndPort>> excludedReplicaSets;
    curTree = readCurrentTree();
    replicaMap = curTree.getResolvedMap(ringConfig.getRingParentName(), new ReplicaNaiveIPPrioritizer());
    excludedReplicaSets = replicaMap.getExcludedReplicaSets(es.asIPAndPortSet(0));
    if (excludedReplicaSets.size() != 0) {
        Log.warning("Exclusion set excludes at least one replica set:");
        for (Set<IPAndPort> s : excludedReplicaSets) {
            Log.warningf("%s", s);
        }
        return true;
    }
    return false;
}
Also used : IPAndPort(com.ms.silverking.net.IPAndPort) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) ReplicaNaiveIPPrioritizer(com.ms.silverking.cloud.dht.daemon.ReplicaNaiveIPPrioritizer) InstantiatedRingTree(com.ms.silverking.cloud.toporing.InstantiatedRingTree) ResolvedReplicaMap(com.ms.silverking.cloud.toporing.ResolvedReplicaMap)

Aggregations

ReplicaNaiveIPPrioritizer (com.ms.silverking.cloud.dht.daemon.ReplicaNaiveIPPrioritizer)2 ExclusionSet (com.ms.silverking.cloud.meta.ExclusionSet)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ServerSetExtensionZK (com.ms.silverking.cloud.meta.ServerSetExtensionZK)1 InstantiatedRingTree (com.ms.silverking.cloud.toporing.InstantiatedRingTree)1 ResolvedReplicaMap (com.ms.silverking.cloud.toporing.ResolvedReplicaMap)1 ZooKeeperExtended (com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)1 IPAndPort (com.ms.silverking.net.IPAndPort)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 KeeperException (org.apache.zookeeper.KeeperException)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1