Search in sources :

Example 1 with ExclusionSet

use of com.ms.silverking.cloud.meta.ExclusionSet in project SilverKing by Morgan-Stanley.

the class DependencyWatcher method build.

private void build(Map<String, Long> curBuild) {
    try {
        boolean buildOK;
        long ringConfigVersion;
        Log.warning("New build triggered");
        buildOK = false;
        ringConfigVersion = -1;
        try {
            if (TopoRingConstants.verbose) {
                System.out.println("Building tree");
            }
            RingTreeRecipe recipe;
            Topology topology;
            WeightSpecifications weightSpecs;
            ExclusionSet exclusionSet;
            ExclusionSet instanceExclusionSet;
            StoragePolicyGroup storagePolicyGroup;
            long topologyVersion;
            long weightsVersion;
            long exclusionVersion;
            long instanceExclusionVersion;
            long storagePolicyGroupVersion;
            RingConfiguration ringConfig;
            ZooKeeperExtended zk;
            HostGroupTable hostGroupTable;
            long hostGroupTableVersion;
            ExclusionSet mergedExclusionSet;
            zk = mc.getZooKeeper();
            topologyVersion = curBuild.get(mp.getTopologyPath());
            weightsVersion = curBuild.get(mp.getWeightsPath());
            exclusionVersion = curBuild.get(mp.getExclusionsPath());
            instanceExclusionVersion = curBuild.get(dhtMC.getMetaPaths().getInstanceExclusionsPath());
            storagePolicyGroupVersion = curBuild.get(mp.getStoragePolicyGroupPath());
            ringConfigVersion = curBuild.get(mp.getConfigPath());
            topology = new TopologyZK(cloudMC).readFromZK(topologyVersion, null);
            weightSpecs = new WeightsZK(mc).readFromZK(weightsVersion, null);
            exclusionSet = new ExclusionSet(new ServerSetExtensionZK(mc, mc.getMetaPaths().getExclusionsPath()).readFromZK(exclusionVersion, null));
            if (options.ignoreInstanceExclusions) {
                instanceExclusionSet = ExclusionSet.emptyExclusionSet(0);
            } else {
                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);
            storagePolicyGroup = new StoragePolicyGroupZK(mc).readFromZK(storagePolicyGroupVersion, null);
            ringConfig = new RingConfigurationZK(mc).readFromZK(ringConfigVersion, null);
            Log.warningf("ringConfiguration %s", ringConfig);
            hostGroupTableVersion = zk.getLatestVersion(cloudMC.getMetaPaths().getHostGroupPath());
            hostGroupTable = new HostGroupTableZK(cloudMC).readFromZK(hostGroupTableVersion, null);
            try {
                recipe = new RingTreeRecipe(topology, ringConfig.getRingParentName(), weightSpecs, mergedExclusionSet, storagePolicyGroup, ringConfig.getStoragePolicyName(), hostGroupTable, ringConfig.getHostGroups(), ringConfigVersion, DHTUtil.currentTimeMillis());
                Log.warning("Recipe.ringParent: " + recipe.ringParent);
            } catch (RuntimeException re) {
                re.printStackTrace(System.out);
                Log.warning("ringConfig: ", ringConfig + " " + re);
                Log.logErrorWarning(re);
                throw re;
            }
            RingTree ringTree;
            RingTree prevRingTree;
            long configInstanceVersion;
            String newInstancePath;
            configInstanceVersion = mc.getLatestConfigInstanceVersion(ringConfigVersion);
            if (configInstanceVersion >= 0 && !ignoreSource) {
                prevRingTree = SingleRingZK.readTree(mc, ringConfigVersion, configInstanceVersion);
            } else {
                prevRingTree = null;
            }
            if (prevRingTree == null || ignoreFeasibility || RingTreeBuilder.convergenceFeasible(prevRingTree, storagePolicyGroup, ringConfig.getStoragePolicyName(), ringConfig.getRingParentName(), exclusionSet)) {
                ringTree = RingTreeBuilder.create(recipe, prevRingTree);
                // ringTree = RingTreeBuilder.create(recipe, null); // for testing without movement reduction
                newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
                SingleRingZK.writeTree(mc, topologyVersion, newInstancePath, ringTree);
                if (TopoRingConstants.verbose) {
                    System.out.println(ringTree);
                    System.out.println(ringConfigVersion);
                    System.out.println(configInstanceVersion);
                    System.out.println(topologyVersion);
                    System.out.println(newInstancePath);
                    System.out.println("Building complete");
                }
                buildOK = true;
            } else {
                Log.warning("Convergence is infeasible. A region in prevTree does not have a viable server.");
            }
        } catch (IOException ioe) {
            Log.logErrorWarning(ioe);
        } catch (KeeperException ke) {
            Log.logErrorWarning(ke);
        }
        if (exitAfterBuild) {
            if (buildOK) {
                try {
                    if (ringConfigVersion < 0) {
                        throw new RuntimeException("ringConfigVersion < 0");
                    }
                    setRing(ringConfigVersion);
                } catch (KeeperException ke) {
                    Log.logErrorWarning(ke);
                    buildOK = false;
                }
            }
            System.exit(buildOK ? 0 : -1);
        }
    } catch (RuntimeException re) {
        re.printStackTrace();
    } finally {
        Log.warning("Leaving build");
    }
}
Also used : RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) HostGroupTable(com.ms.silverking.cloud.config.HostGroupTable) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) Topology(com.ms.silverking.cloud.topology.Topology) IOException(java.io.IOException) StoragePolicyGroupZK(com.ms.silverking.cloud.toporing.meta.StoragePolicyGroupZK) StoragePolicyGroup(com.ms.silverking.cloud.storagepolicy.StoragePolicyGroup) ServerSetExtensionZK(com.ms.silverking.cloud.meta.ServerSetExtensionZK) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException) WeightSpecifications(com.ms.silverking.cloud.toporing.meta.WeightSpecifications) TopologyZK(com.ms.silverking.cloud.topology.TopologyZK) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) WeightsZK(com.ms.silverking.cloud.toporing.meta.WeightsZK) ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) HostGroupTableZK(com.ms.silverking.cloud.meta.HostGroupTableZK) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with ExclusionSet

use of com.ms.silverking.cloud.meta.ExclusionSet 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 3 with ExclusionSet

use of com.ms.silverking.cloud.meta.ExclusionSet in project SilverKing by Morgan-Stanley.

the class StaticRingCreator method createStaticRing.

public static RingCreationResults createStaticRing(String ringName, ZooKeeperConfig zkConfig, Set<String> servers, int replication, UUIDBase myID) {
    try {
        MetaClient mc;
        com.ms.silverking.cloud.meta.MetaClient cloudMC;
        NamedRingConfiguration namedRingConfig;
        RingConfiguration ringConfig;
        RingTreeRecipe recipe;
        Topology topology;
        WeightSpecifications weightSpecs;
        ExclusionSet exclusionSet;
        StoragePolicyGroup storagePolicyGroup;
        HostGroupTable hostGroupTable;
        long ringConfigVersion;
        CloudConfiguration cloudConfig;
        String exclusionSpecsName;
        String hostGroupTableName;
        topology = StaticTopologyCreator.createTopology("topology." + myID, servers);
        exclusionSpecsName = "exclusionSpecs." + myID;
        hostGroupTableName = "hostGroupTable." + myID;
        cloudConfig = new CloudConfiguration(topology.getName(), exclusionSpecsName, hostGroupTableName);
        cloudMC = new com.ms.silverking.cloud.meta.MetaClient(cloudConfig, zkConfig);
        new TopologyZK(cloudMC).writeToZK(topology, null);
        new ExclusionZK(cloudMC).writeToZK(ExclusionSet.emptyExclusionSet(0));
        mc = new MetaClient(NamedRingConfiguration.emptyTemplate.ringName(ringName), zkConfig);
        ringConfig = new RingConfiguration(cloudConfig, "weightSpecsName", StaticTopologyCreator.parentID, SimpleStoragePolicyCreator.storagePolicyGroupName, SimpleStoragePolicyCreator.storagePolicyName, null);
        new RingConfigurationZK(mc).writeToZK(ringConfig, null);
        namedRingConfig = new NamedRingConfiguration(ringName, ringConfig);
        mc = new MetaClient(namedRingConfig, zkConfig);
        EmbeddedSK.setEmbeddedNamedRingConfiguration(ringName, namedRingConfig);
        Log.warning(zkConfig);
        ringConfigVersion = 0;
        weightSpecs = new WeightSpecifications(0);
        exclusionSet = ExclusionSet.emptyExclusionSet(0);
        storagePolicyGroup = SimpleStoragePolicyCreator.createStoragePolicyGroup(replication);
        new StoragePolicyZK(mc).writeToZK(storagePolicyGroup, null);
        hostGroupTable = HostGroupTable.createHostGroupTable(servers, hostGroupName);
        new HostGroupTableZK(cloudMC).writeToZK(hostGroupTable, null);
        recipe = new RingTreeRecipe(topology, StaticTopologyCreator.parentID, weightSpecs, exclusionSet, storagePolicyGroup, SimpleStoragePolicyCreator.storagePolicyName, hostGroupTable, ImmutableSet.of(hostGroupName), ringConfigVersion, DHTUtil.currentTimeMillis());
        Log.warning("Recipe.ringParent: " + recipe.ringParent);
        RingTree ringTree;
        String newInstancePath;
        ringTree = RingTreeBuilder.create(recipe, null);
        newInstancePath = mc.createConfigInstancePath(ringConfigVersion);
        SingleRingZK.writeTree(mc, topology, newInstancePath, ringTree);
        if (TopoRingConstants.verbose) {
            System.out.println(ringTree);
            System.out.println("Building complete");
        }
        return new RingCreationResults(exclusionSpecsName, hostGroupTableName, hostGroupTable, hostGroupName);
    } catch (IOException ioe) {
        Log.logErrorWarning(ioe);
        return null;
    } catch (KeeperException ke) {
        Log.logErrorWarning(ke);
        return null;
    }
}
Also used : MetaClient(com.ms.silverking.cloud.toporing.meta.MetaClient) HostGroupTable(com.ms.silverking.cloud.config.HostGroupTable) RingConfiguration(com.ms.silverking.cloud.toporing.meta.RingConfiguration) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) RingConfigurationZK(com.ms.silverking.cloud.toporing.meta.RingConfigurationZK) ExclusionZK(com.ms.silverking.cloud.meta.ExclusionZK) NamedRingConfiguration(com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration) Topology(com.ms.silverking.cloud.topology.Topology) StoragePolicyZK(com.ms.silverking.cloud.storagepolicy.StoragePolicyZK) IOException(java.io.IOException) StoragePolicyGroup(com.ms.silverking.cloud.storagepolicy.StoragePolicyGroup) WeightSpecifications(com.ms.silverking.cloud.toporing.meta.WeightSpecifications) TopologyZK(com.ms.silverking.cloud.topology.TopologyZK) CloudConfiguration(com.ms.silverking.cloud.meta.CloudConfiguration) ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) HostGroupTableZK(com.ms.silverking.cloud.meta.HostGroupTableZK) KeeperException(org.apache.zookeeper.KeeperException)

Example 4 with ExclusionSet

use of com.ms.silverking.cloud.meta.ExclusionSet in project SilverKing by Morgan-Stanley.

the class SKAdmin method addToInstanceExclusions.

private void addToInstanceExclusions(Set<IPAndPort> serversToAdd) throws KeeperException, IOException {
    ExclusionSet exclusionSet;
    ExclusionSet newExclusionSet;
    exclusionSet = getInstanceExclusions();
    newExclusionSet = exclusionSet.addByIPAndPort(serversToAdd);
    setInstanceExclusions(newExclusionSet);
    System.out.println("............................");
    System.out.println(newExclusionSet);
    System.out.println("----------------------------");
    displayInstanceExclusions();
    System.out.println("============================");
}
Also used : ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet)

Example 5 with ExclusionSet

use of com.ms.silverking.cloud.meta.ExclusionSet in project SilverKing by Morgan-Stanley.

the class SKAdmin method getInstanceExclusions.

private ExclusionSet getInstanceExclusions() throws KeeperException, IOException {
    InstanceExclusionZK instanceExclusionZK;
    ExclusionSet exclusions;
    instanceExclusionZK = new InstanceExclusionZK(dhtMC);
    exclusions = instanceExclusionZK.readFromZK(VersionedDefinition.NO_VERSION, null);
    return exclusions;
}
Also used : ExclusionSet(com.ms.silverking.cloud.meta.ExclusionSet) InstanceExclusionZK(com.ms.silverking.cloud.dht.meta.InstanceExclusionZK)

Aggregations

ExclusionSet (com.ms.silverking.cloud.meta.ExclusionSet)14 IOException (java.io.IOException)8 KeeperException (org.apache.zookeeper.KeeperException)8 ServerSetExtensionZK (com.ms.silverking.cloud.meta.ServerSetExtensionZK)5 ExclusionZK (com.ms.silverking.cloud.meta.ExclusionZK)4 IPAndPort (com.ms.silverking.net.IPAndPort)4 CmdLineException (org.kohsuke.args4j.CmdLineException)4 HostGroupTable (com.ms.silverking.cloud.config.HostGroupTable)3 InstantiatedRingTree (com.ms.silverking.cloud.toporing.InstantiatedRingTree)3 ResolvedReplicaMap (com.ms.silverking.cloud.toporing.ResolvedReplicaMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ReplicaNaiveIPPrioritizer (com.ms.silverking.cloud.dht.daemon.ReplicaNaiveIPPrioritizer)2 InvalidTransitionException (com.ms.silverking.cloud.dht.daemon.storage.convergence.InvalidTransitionException)2 ClassVars (com.ms.silverking.cloud.dht.meta.ClassVars)2 HostGroupTableZK (com.ms.silverking.cloud.meta.HostGroupTableZK)2 StoragePolicyGroup (com.ms.silverking.cloud.storagepolicy.StoragePolicyGroup)2 Topology (com.ms.silverking.cloud.topology.Topology)2 TopologyZK (com.ms.silverking.cloud.topology.TopologyZK)2 InvalidRingException (com.ms.silverking.cloud.toporing.InvalidRingException)2 RingTree (com.ms.silverking.cloud.toporing.RingTree)2