Search in sources :

Example 11 with Node

use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.

the class RingTreeRecipe method _evenlyDistributeWeights.

private static double _evenlyDistributeWeights(Topology topology, Node node, Map<String, Double> nodeWeights, ExclusionSet exclusionList, HostGroupTable hostGroupTable, Set<String> hostGroups) {
    Double weight;
    weight = nodeWeights.get(node.getIDString());
    if (weight == null) {
        if (node.hasChildren()) {
            double sum;
            sum = 0.0;
            for (Node child : node.getChildren()) {
                sum += _evenlyDistributeWeights(topology, child, nodeWeights, exclusionList, hostGroupTable, hostGroups);
            }
            weight = sum;
        } else {
            if (!Sets.intersection(hostGroupTable.getHostGroups(node.getIDString()), hostGroups).isEmpty() && (!exclusionList.contains(node.getIDString()))) {
                weight = WeightSpecifications.defaultWeight;
            } else {
                weight = 0.0;
            }
        }
        nodeWeights.put(node.getIDString(), weight);
    }
    if (debug) {
        System.out.printf("\t####\t%s\t%f\n", node.getIDString(), weight);
    }
    return weight;
}
Also used : Node(com.ms.silverking.cloud.topology.Node)

Example 12 with Node

use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.

the class SingleRingZK method writeTree.

public static void writeTree(MetaClient mc, long topologyVersion, String configInstancePath, RingTree ringTree, Node parent) throws /*, String storagePolicyName*/
KeeperException, IOException {
    assert configInstancePath != null;
    if (parent.hasChildren()) {
        SingleRingZK singleRingZK;
        // singleRingZK = new SingleRingZK(mc, parent.getNodeClass(), topologyVersion, configInstancePath, parent.getIDString(), storagePolicyName);
        singleRingZK = new SingleRingZK(mc, parent.getNodeClass(), topologyVersion, configInstancePath, parent.getIDString());
        singleRingZK.writeToZK(ringTree.getMap(parent.getIDString()), null);
        for (Node child : parent.getChildren()) {
            writeTree(mc, topologyVersion, configInstancePath, ringTree, child);
        }
    }
}
Also used : Node(com.ms.silverking.cloud.topology.Node)

Example 13 with Node

use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.

the class TopologyRingCreator method _create.

/**
 * Create a new ring that is as similar as possible to the ring passed in so
 * that we minimize the movement of data.
 *
 * @param sourceRing
 *            an immutable SingleRing that may or may not meet the
 *            requirements of the recipe
 * @param recipe
 * @return an immutable SingleRing (returned as a TopologyRing) that meets
 *         the requirements of the recipe
 */
private TopologyRing _create(SingleRing sourceRing, RingTreeRecipe recipe, String ringParentID) {
    // This version ignores the source ring, _create2 takes the source into
    // account
    /*
         * Single StoragePolicy applies. StoragePolicy has primary and secondary
         * SubPolicy Each SubPolicy has multiple SubPolicyMembers
         * 
         * Each SubPolicyMember has a logical ring associated with it - The set
         * of nodes in each of these rings is disjoint with respect to all other
         * ring node sets - Weights must be normalized for each member
         * 
         * Loop structure: For {primary, secondary} For all SubPolicyMembers For
         * all replicas
         */
    Node parent;
    NodeClass nodeClass;
    parent = recipe.topology.getNodeByID(ringParentID);
    nodeClass = parent.getChildNodeClass();
    ProtoRegionList prList;
    prList = ProtoRegionList.createEmpty();
    for (SubPolicy subPolicy : recipe.storagePolicy.getSubPolicies()) {
        prList = allocateSubPolicy(prList, subPolicy, ringParentID, recipe);
    }
    System.out.println("*********************");
    System.out.println(prList);
    return prList.toSingleRing(nodeClass, recipe);
}
Also used : NodeClass(com.ms.silverking.cloud.topology.NodeClass) Node(com.ms.silverking.cloud.topology.Node) GenericNode(com.ms.silverking.cloud.topology.GenericNode) SubPolicy(com.ms.silverking.cloud.storagepolicy.SubPolicy)

Example 14 with Node

use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.

the class TopologyRingCreator method swap.

private SwapResult swap(ProtoRegionList prList, Node newNode, int ownedIndex, int nonownedIndex, long maxAllocation) {
    Node existingNode;
    ProtoRegion ownedRegion;
    ProtoRegion nonownedRegion;
    if (debug) {
        System.out.printf("\nin swap %s ownedIndex %d nonownedIndex %d maxAllocation %d\n", newNode, ownedIndex, nonownedIndex, maxAllocation);
        System.out.flush();
    }
    // First make sure that ownedRegion size <= maxAllocation
    ownedRegion = prList.get(ownedIndex);
    if (maxAllocation < ownedRegion.getRegionSize()) {
        if (debug) {
            System.out.println("reducing to max allocation: " + ownedRegion);
        }
        prList.splitProtoRegion(ownedIndex, maxAllocation);
        if (nonownedIndex > ownedIndex) {
            nonownedIndex++;
        }
    }
    // Get the regions (get owned again since it might have been split)
    ownedRegion = prList.get(ownedIndex);
    nonownedRegion = prList.get(nonownedIndex);
    if (debug) {
        System.out.printf("ownedRegion: %s\n", ownedRegion);
        System.out.printf("nonownedRegion: %s\n", nonownedRegion);
    }
    if (ownedRegion.getRegionSize() > nonownedRegion.getRegionSize()) {
        if (debug) {
            System.out.println("splitting ownedRegion");
        }
        prList.splitProtoRegion(ownedIndex, nonownedRegion.getRegionSize());
        if (nonownedIndex > ownedIndex) {
            nonownedIndex++;
        }
    } else if (ownedRegion.getRegionSize() < nonownedRegion.getRegionSize()) {
        if (debug) {
            System.out.println("splitting nonownedRegion");
        }
        prList.splitProtoRegion(nonownedIndex, ownedRegion.getRegionSize());
        if (ownedIndex > nonownedIndex) {
            ownedIndex++;
        }
    } else {
        // no action necessary
        if (debug) {
            System.out.println("no region split necessary");
        }
    }
    // Get the regions again since they might have been split
    ownedRegion = prList.get(ownedIndex);
    nonownedRegion = prList.get(nonownedIndex);
    if (debug) {
        System.out.printf("\townedRegion: %s\n", ownedRegion);
        System.out.printf("\tnonownedRegion: %s\n", nonownedRegion);
    }
    assert ownedRegion.getRegionSize() == nonownedRegion.getRegionSize();
    // Select victim
    existingNode = nonownedRegion.getLastAddedOwnerNotIn(ownedRegion.getOwnersSet());
    // Swap
    nonownedRegion.replaceOwner(existingNode, newNode);
    ownedRegion.replaceOwner(newNode, existingNode);
    if (debug) {
        System.out.println("After swap");
        System.out.printf("\townedRegion: %s\n", ownedRegion);
        System.out.printf("\tnonownedRegion: %s\n", nonownedRegion);
    }
    return new SwapResult(ownedIndex, nonownedIndex, ownedRegion.getRegionSize());
}
Also used : Node(com.ms.silverking.cloud.topology.Node) GenericNode(com.ms.silverking.cloud.topology.GenericNode)

Example 15 with Node

use of com.ms.silverking.cloud.topology.Node in project SilverKing by Morgan-Stanley.

the class TopologyRingCreator method allocateSubPolicy2.

private void allocateSubPolicy2(SingleRing sourceRing, ProtoRegionList prList, SubPolicy subPolicy, String ringParentID, RingTreeRecipe recipe) {
    Node parent;
    if (debug) {
        System.out.println("TopologyRingCreator.allocateSubPolicy2()");
        System.out.println("subPolicy: " + subPolicy);
        System.out.flush();
    }
    parent = recipe.topology.getNodeByID(ringParentID);
    for (SubPolicyMember member : subPolicy.getMembers()) {
        allocateSubPolicyMember2(sourceRing, prList, member, recipe, parent, subPolicy.getReplicationType());
    }
}
Also used : Node(com.ms.silverking.cloud.topology.Node) GenericNode(com.ms.silverking.cloud.topology.GenericNode) SubPolicyMember(com.ms.silverking.cloud.storagepolicy.SubPolicyMember)

Aggregations

Node (com.ms.silverking.cloud.topology.Node)50 GenericNode (com.ms.silverking.cloud.topology.GenericNode)17 DHTNode (com.ms.silverking.cloud.dht.daemon.DHTNode)10 ImmutableSet (com.google.common.collect.ImmutableSet)6 IPAndPort (com.ms.silverking.net.IPAndPort)5 NodeClass (com.ms.silverking.cloud.topology.NodeClass)4 SubPolicy (com.ms.silverking.cloud.storagepolicy.SubPolicy)2 SubPolicyMember (com.ms.silverking.cloud.storagepolicy.SubPolicyMember)2 RingInteger (com.ms.silverking.numeric.RingInteger)2 ImmutableList (com.google.common.collect.ImmutableList)1 HostGroupTable (com.ms.silverking.cloud.config.HostGroupTable)1 PolicyParser (com.ms.silverking.cloud.storagepolicy.PolicyParser)1 StoragePolicy (com.ms.silverking.cloud.storagepolicy.StoragePolicy)1 StoragePolicyGroup (com.ms.silverking.cloud.storagepolicy.StoragePolicyGroup)1 Topology (com.ms.silverking.cloud.topology.Topology)1 WeightSpecifications (com.ms.silverking.cloud.toporing.meta.WeightSpecifications)1 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)1 Stopwatch (com.ms.silverking.time.Stopwatch)1 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1