Search in sources :

Example 76 with DiscoveryEvent

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

the class GridSpiTestContext method resetNodes.

/**
 * @param nodes Nodes to reset.
 * @param rmv Whether nodes that were not passed in should be removed or not.
 */
public void resetNodes(Collection<ClusterNode> nodes, boolean rmv) {
    for (ClusterNode node : nodes) {
        assert !node.equals(locNode);
        if (!rmtNodes.contains(node))
            addNode(node);
    }
    if (rmv) {
        for (Iterator<ClusterNode> iter = rmtNodes.iterator(); iter.hasNext(); ) {
            ClusterNode node = iter.next();
            if (!nodes.contains(node)) {
                iter.remove();
                notifyListener(new DiscoveryEvent(locNode, "Node left", EVT_NODE_LEFT, node));
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 77 with DiscoveryEvent

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

the class GridSpiTestContext method addNode.

/**
 * @param node Node to add.
 */
public void addNode(ClusterNode node) {
    rmtNodes.add(node);
    notifyListener(new DiscoveryEvent(locNode, "Node joined", EVT_NODE_JOINED, node));
}
Also used : DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 78 with DiscoveryEvent

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

the class TcpClientDiscoverySpiFailureTimeoutSelfTest method testFailureTimeout3Server.

/**
 * Test failure detection time between servers with failure detection.
 *
 * @throws Exception in case of error.
 */
public void testFailureTimeout3Server() throws Exception {
    failureThreshold = 1000;
    clientFailureDetectionTimeout = 10000;
    useTestSpi = true;
    try {
        startServerNodes(3);
        checkNodes(3, 0);
        Ignite srv0 = G.ignite("server-0");
        final TestTcpDiscoverySpi2 spi0 = (TestTcpDiscoverySpi2) srv0.configuration().getDiscoverySpi();
        final Ignite srv1 = G.ignite("server-1");
        final TestTcpDiscoverySpi2 spi1 = (TestTcpDiscoverySpi2) srv1.configuration().getDiscoverySpi();
        Ignite srv2 = G.ignite("server-2");
        final TestTcpDiscoverySpi2 spi2 = (TestTcpDiscoverySpi2) srv2.configuration().getDiscoverySpi();
        long failureTime = U.currentTimeMillis();
        final AtomicLong failureDetectTime = new AtomicLong();
        final CountDownLatch latch = new CountDownLatch(2);
        spi1.writeToSocketDelay = 2000;
        for (Ignite srv : new Ignite[] { srv0, srv2 }) {
            srv.events().localListen(new IgnitePredicate<Event>() {

                @Override
                public boolean apply(Event evt) {
                    DiscoveryEvent evt0 = (DiscoveryEvent) evt;
                    assertEquals(srv1.cluster().localNode().id(), evt0.eventNode().id());
                    failureDetectTime.compareAndSet(0, U.currentTimeMillis());
                    latch.countDown();
                    return true;
                }
            }, EVT_NODE_FAILED);
        }
        assertTrue("Can't get node failure event", latch.await(15000, TimeUnit.MILLISECONDS));
        long detectTime = failureDetectTime.get() - failureTime;
        assertTrue("Server node failure detected too fast: " + detectTime + "ms", detectTime > failureThreshold - 100);
        assertTrue("Server node failure detected too slow:  " + detectTime + "ms", detectTime < clientFailureDetectionTimeout);
    } finally {
        failureThreshold = FAILURE_THRESHOLD;
        useTestSpi = false;
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 79 with DiscoveryEvent

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

the class TcpClientDiscoverySpiFailureTimeoutSelfTest method clientReconnectOnCoordinatorRouterFail.

/**
 * Test tries to provoke scenario when client sends reconnect message before router failure detected.
 *
 * @param srvNodes Number of additional server nodes.
 * @throws Exception If failed.
 */
public void clientReconnectOnCoordinatorRouterFail(int srvNodes) throws Exception {
    startServerNodes(1);
    Ignite srv = G.ignite("server-0");
    final TcpDiscoveryNode srvNode = (TcpDiscoveryNode) srv.cluster().localNode();
    final UUID srvNodeId = srvNode.id();
    clientIpFinder = new TcpDiscoveryVmIpFinder();
    clientIpFinder.setAddresses(Collections.singleton("localhost:" + srvNode.discoveryPort() + ".." + (srvNode.discoveryPort() + 1)));
    failureThreshold = 1000L;
    netTimeout = 1000L;
    // Client should connect to coordinator.
    startClientNodes(1);
    failureThreshold = 10_000L;
    netTimeout = 5000L;
    List<String> nodes = new ArrayList<>();
    for (int i = 0; i < srvNodes; i++) {
        Ignite g = startGrid("server-" + srvIdx.getAndIncrement());
        nodes.add(g.name());
        srvNodeIds.add(g.cluster().localNode().id());
    }
    checkNodes(1 + srvNodes, 1);
    nodes.add("client-0");
    final CountDownLatch latch = new CountDownLatch(nodes.size());
    final AtomicBoolean err = new AtomicBoolean();
    for (String node : nodes) {
        G.ignite(node).events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                DiscoveryEvent disoEvt = (DiscoveryEvent) evt;
                if (disoEvt.eventNode().id().equals(srvNodeId)) {
                    info("Expected node failed event: " + ((DiscoveryEvent) evt).eventNode());
                    latch.countDown();
                } else {
                    log.info("Unexpected node failed event: " + evt);
                    err.set(true);
                }
                return true;
            }
        }, EVT_NODE_FAILED);
    }
    Thread.sleep(5000);
    Ignite client = G.ignite("client-0");
    UUID nodeId = client.cluster().localNode().id();
    log.info("Fail coordinator: " + srvNodeId);
    TestTcpDiscoverySpi srvSpi = (TestTcpDiscoverySpi) srv.configuration().getDiscoverySpi();
    srvSpi.pauseAll(false);
    try {
        Thread.sleep(2000);
    } finally {
        srvSpi.simulateNodeFailure();
        srvSpi.resumeAll();
    }
    try {
        assertTrue(latch.await(failureThreshold + 3000, TimeUnit.MILLISECONDS));
        assertFalse("Unexpected event, see log for details.", err.get());
        assertEquals(nodeId, client.cluster().localNode().id());
    } finally {
        srvSpi.resumeAll();
    }
}
Also used : TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 80 with DiscoveryEvent

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

the class GridReduceQueryExecutor method start.

/**
 * @param ctx Context.
 * @param h2 H2 Indexing.
 * @throws IgniteCheckedException If failed.
 */
public void start(final GridKernalContext ctx, final IgniteH2Indexing h2) throws IgniteCheckedException {
    this.ctx = ctx;
    this.h2 = h2;
    log = ctx.log(GridReduceQueryExecutor.class);
    ctx.io().addMessageListener(GridTopic.TOPIC_QUERY, new GridMessageListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            if (!busyLock.enterBusy())
                return;
            try {
                if (msg instanceof GridCacheQueryMarshallable)
                    ((GridCacheQueryMarshallable) msg).unmarshall(ctx.config().getMarshaller(), ctx);
                GridReduceQueryExecutor.this.onMessage(nodeId, msg);
            } finally {
                busyLock.leaveBusy();
            }
        }
    });
    ctx.event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(final Event evt) {
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            for (ReduceQueryRun r : runs.values()) {
                for (GridMergeIndex idx : r.indexes()) {
                    if (idx.hasSource(nodeId)) {
                        handleNodeLeft(r, nodeId);
                        break;
                    }
                }
            }
            for (DistributedUpdateRun r : updRuns.values()) r.handleNodeLeft(nodeId);
        }
    }, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) GridCacheQueryMarshallable(org.apache.ignite.internal.processors.cache.query.GridCacheQueryMarshallable) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID)

Aggregations

DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)83 Event (org.apache.ignite.events.Event)54 UUID (java.util.UUID)39 ClusterNode (org.apache.ignite.cluster.ClusterNode)32 CountDownLatch (java.util.concurrent.CountDownLatch)24 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)24 Ignite (org.apache.ignite.Ignite)23 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)11 List (java.util.List)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 JobEvent (org.apache.ignite.events.JobEvent)8 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)7 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)7 IgniteException (org.apache.ignite.IgniteException)6 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)6