Search in sources :

Example 6 with DiscoverySpiListener

use of org.apache.ignite.spi.discovery.DiscoverySpiListener in project ignite by apache.

the class ServerImpl method notifyDiscovery.

/**
     * Notify external listener on discovery event.
     *
     * @param type Discovery event type. See {@link org.apache.ignite.events.DiscoveryEvent} for more details.
     * @param topVer Topology version.
     * @param node Remote node this event is connected with.
     */
private void notifyDiscovery(int type, long topVer, TcpDiscoveryNode node) {
    assert type > 0;
    assert node != null;
    DiscoverySpiListener lsnr = spi.lsnr;
    TcpDiscoverySpiState spiState = spiStateCopy();
    DebugLogger log = type == EVT_NODE_METRICS_UPDATED ? traceLog : debugLog;
    if (lsnr != null && node.visible() && (spiState == CONNECTED || spiState == DISCONNECTING)) {
        if (log.isDebugEnabled())
            log.debug("Discovery notification [node=" + node + ", spiState=" + spiState + ", type=" + U.gridEventName(type) + ", topVer=" + topVer + ']');
        Collection<ClusterNode> top = upcast(ring.visibleNodes());
        Map<Long, Collection<ClusterNode>> hist = updateTopologyHistory(topVer, top);
        lsnr.onDiscovery(type, topVer, node, top, hist, null);
    } else {
        if (log.isDebugEnabled())
            log.debug("Skipped discovery notification [node=" + node + ", spiState=" + spiState + ", type=" + U.gridEventName(type) + ", topVer=" + topVer + ']');
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TcpDiscoverySpiState(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoverySpiState) Collection(java.util.Collection) DiscoverySpiListener(org.apache.ignite.spi.discovery.DiscoverySpiListener)

Example 7 with DiscoverySpiListener

use of org.apache.ignite.spi.discovery.DiscoverySpiListener in project ignite by apache.

the class ServerImpl method spiStop0.

/**
     * Stops SPI finally or stops SPI for restart.
     *
     * @param disconnect {@code True} if SPI is being disconnected.
     * @throws IgniteSpiException If failed.
     */
private void spiStop0(boolean disconnect) throws IgniteSpiException {
    if (log.isDebugEnabled()) {
        if (disconnect)
            log.debug("Disconnecting SPI.");
        else
            log.debug("Preparing to start local node stop procedure.");
    }
    if (disconnect) {
        synchronized (mux) {
            spiState = DISCONNECTING;
        }
    }
    if (msgWorker != null && msgWorker.isAlive() && !disconnect) {
        // Send node left message only if it is final stop.
        msgWorker.addMessage(new TcpDiscoveryNodeLeftMessage(locNode.id()));
        synchronized (mux) {
            long timeout = spi.netTimeout;
            long threshold = U.currentTimeMillis() + timeout;
            while (spiState != LEFT && timeout > 0) {
                try {
                    mux.wait(timeout);
                    timeout = threshold - U.currentTimeMillis();
                } catch (InterruptedException ignored) {
                    Thread.currentThread().interrupt();
                    break;
                }
            }
            if (spiState == LEFT) {
                if (log.isDebugEnabled())
                    log.debug("Verification for local node leave has been received from coordinator" + " (continuing stop procedure).");
            } else if (log.isInfoEnabled()) {
                log.info("No verification for local node leave has been received from coordinator" + " (will stop node anyway).");
            }
        }
    }
    U.interrupt(tcpSrvr);
    U.join(tcpSrvr, log);
    tcpSrvr = null;
    Collection<SocketReader> tmp;
    synchronized (mux) {
        tmp = U.arrayList(readers);
    }
    U.interrupt(tmp);
    U.joinThreads(tmp, log);
    U.interrupt(ipFinderCleaner);
    U.join(ipFinderCleaner, log);
    U.interrupt(msgWorker);
    U.join(msgWorker, log);
    for (ClientMessageWorker clientWorker : clientMsgWorkers.values()) {
        U.interrupt(clientWorker);
        U.join(clientWorker, log);
    }
    clientMsgWorkers.clear();
    IgniteUtils.shutdownNow(ServerImpl.class, utilityPool, log);
    U.interrupt(statsPrinter);
    U.join(statsPrinter, log);
    Collection<TcpDiscoveryNode> rmts = null;
    Collection<TcpDiscoveryNode> nodes = null;
    if (!disconnect)
        spi.printStopInfo();
    else {
        spi.getSpiContext().deregisterPorts();
        nodes = ring.visibleNodes();
        rmts = F.view(nodes, F.remoteNodes(locNode.id()));
    }
    long topVer = ring.topologyVersion();
    ring.clear();
    if (rmts != null && !rmts.isEmpty()) {
        // This is restart/disconnection and remote nodes are not empty.
        // We need to fire FAIL event for each.
        DiscoverySpiListener lsnr = spi.lsnr;
        if (lsnr != null) {
            Collection<ClusterNode> processed = new HashSet<>();
            for (TcpDiscoveryNode n : rmts) {
                assert n.visible();
                processed.add(n);
                List<ClusterNode> top = U.arrayList(nodes, F.notIn(processed));
                topVer++;
                Map<Long, Collection<ClusterNode>> hist = updateTopologyHistory(topVer, Collections.unmodifiableList(top));
                lsnr.onDiscovery(EVT_NODE_FAILED, topVer, n, top, hist, null);
            }
        }
    }
    printStatistics();
    spi.stats.clear();
    synchronized (mux) {
        // Clear stored data.
        leavingNodes.clear();
        failedNodes.clear();
        spiState = DISCONNECTED;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoverySpiListener(org.apache.ignite.spi.discovery.DiscoverySpiListener) Collection(java.util.Collection) TcpDiscoveryNodeLeftMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) GridBoundedLinkedHashSet(org.apache.ignite.internal.util.GridBoundedLinkedHashSet) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet)

Aggregations

DiscoverySpiListener (org.apache.ignite.spi.discovery.DiscoverySpiListener)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Collection (java.util.Collection)3 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 TcpDiscoveryNode (org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 ClusterMetricsSnapshot (org.apache.ignite.internal.ClusterMetricsSnapshot)1