Search in sources :

Example 11 with DiscoveryEvent

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

the class IgniteSpiAdapter method onContextInitialized.

/** {@inheritDoc} */
@Override
public final void onContextInitialized(final IgniteSpiContext spiCtx) throws IgniteSpiException {
    assert spiCtx != null;
    this.spiCtx = spiCtx;
    if (!Boolean.getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
        spiCtx.addLocalEventListener(paramsLsnr = new GridLocalEventListener() {

            @Override
            public void onEvent(Event evt) {
                assert evt instanceof DiscoveryEvent : "Invalid event [expected=" + EVT_NODE_JOINED + ", actual=" + evt.type() + ", evt=" + evt + ']';
                ClusterNode node = spiCtx.node(((DiscoveryEvent) evt).eventNode().id());
                if (node != null)
                    try {
                        checkConfigurationConsistency(spiCtx, node, false);
                        checkConfigurationConsistency0(spiCtx, node, false);
                    } catch (IgniteSpiException e) {
                        U.error(log, "Spi consistency check failed [node=" + node.id() + ", spi=" + getName() + ']', e);
                    }
            }
        }, EVT_NODE_JOINED);
        final Collection<ClusterNode> remotes = F.concat(false, spiCtx.remoteNodes(), spiCtx.remoteDaemonNodes());
        for (ClusterNode node : remotes) {
            checkConfigurationConsistency(spiCtx, node, true);
            checkConfigurationConsistency0(spiCtx, node, true);
        }
    }
    onContextInitialized0(spiCtx);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 12 with DiscoveryEvent

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

the class AbstractAffinityFunctionSelfTest method checkRandomReassignment.

/**
     * @param backups Backups.
     */
protected void checkRandomReassignment(int backups) {
    AffinityFunction aff = affinityFunction();
    Random rnd = new Random();
    int maxNodes = 50;
    List<ClusterNode> nodes = new ArrayList<>(maxNodes);
    List<List<ClusterNode>> prev = null;
    int state = 0;
    int i = 0;
    while (true) {
        boolean add;
        if (nodes.size() < 2) {
            // Returned back to one node?
            if (state == 1)
                return;
            add = true;
        } else if (nodes.size() == maxNodes) {
            if (state == 0)
                state = 1;
            add = false;
        } else {
            // Nodes size in [2, maxNodes - 1].
            if (state == 0)
                // 66% to add, 33% to remove.
                add = rnd.nextInt(3) != 0;
            else
                // 33% to add, 66% to remove.
                add = rnd.nextInt(3) == 0;
        }
        DiscoveryEvent discoEvt;
        if (add) {
            ClusterNode addedNode = new GridTestNode(UUID.randomUUID());
            nodes.add(addedNode);
            discoEvt = new DiscoveryEvent(addedNode, "", EventType.EVT_NODE_JOINED, addedNode);
        } else {
            ClusterNode rmvNode = nodes.remove(rnd.nextInt(nodes.size()));
            discoEvt = new DiscoveryEvent(rmvNode, "", EventType.EVT_NODE_LEFT, rmvNode);
        }
        info("======================================");
        info("Assigning partitions [iter=" + i + ", discoEvt=" + discoEvt + ", nodesSize=" + nodes.size() + ']');
        info("======================================");
        List<List<ClusterNode>> assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
        verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
        prev = assignment;
        i++;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with DiscoveryEvent

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

the class RendezvousAffinityFunctionSimpleBenchmark method addNode.

/**
     * @param nodes Topology.
     * @param iter Iteration count.
     * @return Discovery event.
     */
@NotNull
private DiscoveryEvent addNode(List<ClusterNode> nodes, int iter) {
    GridTestNode node = new GridTestNode(UUID.randomUUID());
    // two neighbours nodes
    node.setAttribute(IgniteNodeAttributes.ATTR_MACS, MAC_PREF + "_add_" + iter / 4);
    nodes.add(node);
    return new DiscoveryEvent(nodes.get(0), "", EventType.EVT_NODE_JOINED, node);
}
Also used : DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridTestNode(org.apache.ignite.testframework.GridTestNode) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with DiscoveryEvent

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

the class RendezvousAffinityFunctionSimpleBenchmark method nodesModificationChangeLast.

/**
     * Modify the topology by remove the last / add new node.
     *
     * @param nodes Topology.
     * @param prevAssignment Previous afinity.
     * @param iter Number of iteration.
     * @param backups Backups count.
     * @return Affinity context.
     */
private GridAffinityFunctionContextImpl nodesModificationChangeLast(List<ClusterNode> nodes, List<List<ClusterNode>> prevAssignment, int iter, int backups) {
    DiscoveryEvent discoEvt;
    discoEvt = iter % 2 == 0 ? addNode(nodes, iter) : removeNode(nodes, nodes.size() - 1);
    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)

Example 15 with DiscoveryEvent

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

the class IgniteClientReconnectCacheTest method testReconnectInitialExchangeInProgress.

/**
     * @throws Exception If failed.
     */
public void testReconnectInitialExchangeInProgress() throws Exception {
    final UUID clientId = UUID.randomUUID();
    Ignite srv = grid(0);
    final CountDownLatch joinLatch = new CountDownLatch(1);
    srv.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_NODE_JOINED && ((DiscoveryEvent) evt).eventNode().id().equals(clientId)) {
                info("Client joined: " + evt);
                joinLatch.countDown();
            }
            return true;
        }
    }, EVT_NODE_JOINED);
    TestCommunicationSpi srvCommSpi = (TestCommunicationSpi) srv.configuration().getCommunicationSpi();
    srvCommSpi.blockMessages(GridDhtPartitionsFullMessage.class, clientId);
    clientMode = true;
    nodeId = clientId;
    IgniteInternalFuture<Boolean> fut = GridTestUtils.runAsync(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                Ignition.start(optimize(getConfiguration(getTestIgniteInstanceName(SRV_CNT))));
                return true;
            } catch (IgniteClientDisconnectedException e) {
                log.info("Expected start error: " + e);
                try {
                    e.reconnectFuture().get();
                    fail();
                } catch (IgniteException e0) {
                    log.info("Expected future error: " + e0);
                }
                return true;
            } catch (Throwable e) {
                log.error("Unexpected error: " + e, e);
                throw e;
            }
        }
    });
    TestTcpDiscoverySpi srvSpi = spi(srv);
    try {
        if (!joinLatch.await(10_000, MILLISECONDS)) {
            log.error("Failed to wait for join event, will dump threads.");
            U.dumpThreads(log);
            fail("Failed to wait for join event.");
        }
        U.sleep(1000);
        assertNotDone(fut);
        srvSpi.failNode(clientId, null);
    } finally {
        srvCommSpi.stopBlock(false);
    }
    assertTrue(fut.get());
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

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