Search in sources :

Example 66 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class RendezvousAffinityFunctionSimpleBenchmark method assignPartitions.

/**
     *
     * @param aff Affinity function.
     * @param nodes Topology.
     * @param iter Number of iteration.
     * @param prevAssignment Previous affinity assignment.
     * @param backups Backups count.
     * @return Tuple with affinity and time spend of the affinity calculation.
     */
private IgniteBiTuple<Long, List<List<ClusterNode>>> assignPartitions(AffinityFunction aff, List<ClusterNode> nodes, List<List<ClusterNode>> prevAssignment, int backups, int iter) {
    GridAffinityFunctionContextImpl ctx = null;
    switch(mode) {
        case CHANGE_LAST_NODE:
            ctx = nodesModificationChangeLast(nodes, prevAssignment, iter, backups);
            break;
        case CHANGE_FIRST_NODE:
            ctx = nodesModificationChangeFirst(nodes, prevAssignment, iter, backups);
            break;
        case ADD:
            ctx = new GridAffinityFunctionContextImpl(nodes, prevAssignment, addNode(nodes, iter), new AffinityTopologyVersion(nodes.size()), backups);
            break;
        case REMOVE_RANDOM:
            ctx = new GridAffinityFunctionContextImpl(nodes, prevAssignment, removeNode(nodes, nodes.size() - 1), new AffinityTopologyVersion(nodes.size()), backups);
            break;
        case NONE:
            ctx = new GridAffinityFunctionContextImpl(nodes, prevAssignment, new DiscoveryEvent(nodes.get(0), "", EventType.EVT_NODE_JOINED, nodes.get(nodes.size() - 1)), new AffinityTopologyVersion(nodes.size()), backups);
            break;
    }
    long start = System.currentTimeMillis();
    List<List<ClusterNode>> assignments = aff.assignPartitions(ctx);
    return F.t(System.currentTimeMillis() - start, assignments);
}
Also used : GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 67 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class AbstractAffinityFunctionSelfTest method checkNodeRemoved.

/**
     * @throws Exception If failed.
     */
protected void checkNodeRemoved(int backups, int neighborsPerHost, int neighborsPeriod) throws Exception {
    AffinityFunction aff = affinityFunction();
    int nodesCnt = 50;
    List<ClusterNode> nodes = new ArrayList<>(nodesCnt);
    List<List<ClusterNode>> prev = null;
    for (int i = 0; i < nodesCnt; i++) {
        info("======================================");
        info("Assigning partitions: " + i);
        info("======================================");
        ClusterNode node = new GridTestNode(UUID.randomUUID());
        if (neighborsPerHost > 0)
            node.attribute(MAC_PREF + ((i / neighborsPeriod) % (nodesCnt / neighborsPerHost)));
        nodes.add(node);
        DiscoveryEvent discoEvt = new DiscoveryEvent(node, "", EventType.EVT_NODE_JOINED, node);
        GridAffinityFunctionContextImpl ctx = new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups);
        List<List<ClusterNode>> assignment = aff.assignPartitions(ctx);
        info("Assigned.");
        verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
        prev = assignment;
    }
    info("======================================");
    info("Will remove nodes.");
    info("======================================");
    for (int i = 0; i < nodesCnt - 1; i++) {
        info("======================================");
        info("Assigning partitions: " + i);
        info("======================================");
        ClusterNode rmv = nodes.remove(nodes.size() - 1);
        DiscoveryEvent discoEvt = new DiscoveryEvent(rmv, "", EventType.EVT_NODE_LEFT, rmv);
        List<List<ClusterNode>> assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
        info("Assigned.");
        verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
        prev = assignment;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) ArrayList(java.util.ArrayList) List(java.util.List) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 68 with DiscoveryEvent

use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.

the class RendezvousAffinityFunctionSimpleBenchmark method nodesModificationChangeFirst.

/**
     * Modify the topology by remove the first node / add new node
     *
     * @param nodes Topology.
     * @param prevAssignment Previous affinity.
     * @param iter Number of iteration.
     * @param backups Backups count.
     * @return Affinity context.
     */
private GridAffinityFunctionContextImpl nodesModificationChangeFirst(List<ClusterNode> nodes, List<List<ClusterNode>> prevAssignment, int iter, int backups) {
    DiscoveryEvent discoEvt;
    discoEvt = iter % 2 == 0 ? addNode(nodes, iter) : removeNode(nodes, 0);
    return new GridAffinityFunctionContextImpl(nodes, prevAssignment, discoEvt, new AffinityTopologyVersion(nodes.size()), backups);
}
Also used : GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Aggregations

DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)68 Event (org.apache.ignite.events.Event)49 UUID (java.util.UUID)36 ClusterNode (org.apache.ignite.cluster.ClusterNode)27 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)22 Ignite (org.apache.ignite.Ignite)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)14 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 List (java.util.List)9 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 JobEvent (org.apache.ignite.events.JobEvent)8 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IgniteException (org.apache.ignite.IgniteException)5 HashMap (java.util.HashMap)4