Search in sources :

Example 56 with DiscoveryEvent

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

the class GridCachePartitionExchangeManager method initialExchangeId.

/**
 * @return Initial exchange ID.
 */
private GridDhtPartitionExchangeId initialExchangeId() {
    DiscoveryEvent discoEvt = cctx.discovery().localJoinEvent();
    assert discoEvt != null;
    final AffinityTopologyVersion startTopVer = affinityTopologyVersion(discoEvt);
    assert discoEvt.topologyVersion() == startTopVer.topologyVersion();
    return exchangeId(cctx.localNode().id(), startTopVer, discoEvt);
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 57 with DiscoveryEvent

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

the class GridCacheDeploymentManager method start0.

/**
 * {@inheritDoc}
 */
@Override
public void start0() throws IgniteCheckedException {
    globalLdr = new CacheClassLoader(cctx.gridConfig().getClassLoader());
    depEnabled = cctx.gridDeploy().enabled();
    if (depEnabled) {
        discoLsnr = new GridLocalEventListener() {

            @Override
            public void onEvent(Event evt) {
                assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT : "Unexpected event: " + evt;
                UUID id = ((DiscoveryEvent) evt).eventNode().id();
                if (log.isDebugEnabled())
                    log.debug("Processing node departure: " + id);
                for (Map.Entry<IgniteUuid, CachedDeploymentInfo<K, V>> entry : deps.entrySet()) {
                    CachedDeploymentInfo<K, V> d = entry.getValue();
                    if (log.isDebugEnabled())
                        log.debug("Examining cached info: " + d);
                    if (d.senderId().equals(id) || d.removeParticipant(id)) {
                        deps.remove(entry.getKey(), d);
                        if (log.isDebugEnabled())
                            log.debug("Removed cached info [d=" + d + ", deps=" + deps + ']');
                    }
                }
                allParticipants.remove(id);
            }
        };
        cctx.gridEvents().addLocalEventListener(discoLsnr, EVT_NODE_LEFT, EVT_NODE_FAILED);
    }
}
Also used : 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) UUID(java.util.UUID)

Example 58 with DiscoveryEvent

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

the class GridCachePartitionExchangeManager method mergeExchanges.

/**
 * @param curFut Current exchange future.
 * @param msg Message.
 * @return {@code True} if node is stopping.
 * @throws IgniteInterruptedCheckedException If interrupted.
 */
public boolean mergeExchanges(final GridDhtPartitionsExchangeFuture curFut, GridDhtPartitionsFullMessage msg) throws IgniteInterruptedCheckedException {
    AffinityTopologyVersion resVer = msg.resultTopologyVersion();
    if (exchWorker.waitForExchangeFuture(resVer))
        return true;
    for (CachePartitionExchangeWorkerTask task : exchWorker.futQ) {
        if (task instanceof GridDhtPartitionsExchangeFuture) {
            GridDhtPartitionsExchangeFuture fut = (GridDhtPartitionsExchangeFuture) task;
            if (fut.initialVersion().compareTo(resVer) > 0) {
                if (log.isInfoEnabled()) {
                    log.info("Merge exchange future on finish stop [curFut=" + curFut.initialVersion() + ", resVer=" + resVer + ", nextFutVer=" + fut.initialVersion() + ']');
                }
                break;
            }
            if (log.isInfoEnabled()) {
                log.info("Merge exchange future on finish [curFut=" + curFut.initialVersion() + ", mergedFut=" + fut.initialVersion() + ", evt=" + IgniteUtils.gridEventName(fut.firstEvent().type()) + ", evtNode=" + fut.firstEvent().eventNode().id() + ", evtNodeClient=" + CU.clientNode(fut.firstEvent().eventNode()) + ']');
            }
            DiscoveryEvent evt = fut.firstEvent();
            curFut.context().events().addEvent(fut.initialVersion(), fut.firstEvent(), fut.firstEventCache());
            if (evt.type() == EVT_NODE_JOINED) {
                final GridDhtPartitionsSingleMessage pendingMsg = fut.mergeJoinExchangeOnDone(curFut);
                if (pendingMsg != null) {
                    if (log.isInfoEnabled()) {
                        log.info("Merged join exchange future on finish, will reply to node [" + "curFut=" + curFut.initialVersion() + ", mergedFut=" + fut.initialVersion() + ", evtNode=" + evt.eventNode().id() + ']');
                    }
                    curFut.waitAndReplyToNode(evt.eventNode().id(), pendingMsg);
                }
            }
        }
    }
    ExchangeDiscoveryEvents evts = curFut.context().events();
    assert evts.topologyVersion().equals(resVer) : "Invalid exchange merge result [ver=" + evts.topologyVersion() + ", expVer=" + resVer + ']';
    return false;
}
Also used : GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 59 with DiscoveryEvent

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

the class GridDeploymentPerLoaderStore method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    ctxLdr = U.detectClassLoader(getClass());
    discoLsnr = new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt instanceof DiscoveryEvent;
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            if (evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED) {
                Collection<IsolatedDeployment> rmv = new LinkedList<>();
                synchronized (mux) {
                    for (Iterator<IsolatedDeployment> iter = cache.values().iterator(); iter.hasNext(); ) {
                        IsolatedDeployment dep = iter.next();
                        if (dep.senderNodeId().equals(nodeId)) {
                            dep.undeploy();
                            iter.remove();
                            rmv.add(dep);
                        }
                    }
                }
                for (IsolatedDeployment dep : rmv) dep.recordUndeployed();
            }
        }
    };
    ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT);
    if (log.isDebugEnabled())
        log.debug(startInfo());
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) Iterator(java.util.Iterator) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DeploymentEvent(org.apache.ignite.events.DeploymentEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Collection(java.util.Collection) UUID(java.util.UUID)

Example 60 with DiscoveryEvent

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

the class GridIoManager method onKernalStart0.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "deprecation", "SynchronizationOnLocalVariableOrMethodParameter" })
@Override
public void onKernalStart0() throws IgniteCheckedException {
    discoLsnr = new GridLocalEventListener() {

        @SuppressWarnings({ "TooBroadScope", "fallthrough" })
        @Override
        public void onEvent(Event evt) {
            assert evt instanceof DiscoveryEvent : "Invalid event: " + evt;
            DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
            UUID nodeId = discoEvt.eventNode().id();
            switch(evt.type()) {
                case EVT_NODE_JOINED:
                    // We can't receive messages from undiscovered nodes.
                    assert waitMap.get(nodeId) == null;
                    break;
                case EVT_NODE_LEFT:
                case EVT_NODE_FAILED:
                    for (Map.Entry<Object, ConcurrentMap<UUID, GridCommunicationMessageSet>> e : msgSetMap.entrySet()) {
                        ConcurrentMap<UUID, GridCommunicationMessageSet> map = e.getValue();
                        GridCommunicationMessageSet set;
                        boolean empty;
                        synchronized (map) {
                            set = map.remove(nodeId);
                            empty = map.isEmpty();
                        }
                        if (set != null) {
                            if (log.isDebugEnabled())
                                log.debug("Removed message set due to node leaving grid: " + set);
                            // Unregister timeout listener.
                            ctx.timeout().removeTimeoutObject(set);
                            // Node may still send stale messages for this topic
                            // even after discovery notification is done.
                            closedTopics.add(set.topic());
                        }
                        if (empty)
                            msgSetMap.remove(e.getKey(), map);
                    }
                    // Clean up delayed and ordered messages (need exclusive lock).
                    lock.writeLock().lock();
                    try {
                        Deque<DelayedMessage> waitList = waitMap.remove(nodeId);
                        if (log.isDebugEnabled())
                            log.debug("Removed messages from discovery startup delay list " + "(sender node left topology): " + waitList);
                    } finally {
                        lock.writeLock().unlock();
                    }
                    break;
                default:
                    assert false : "Unexpected event: " + evt;
            }
        }
    };
    ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_NODE_FAILED);
    // Make sure that there are no stale messages due to window between communication
    // manager start and kernal start.
    // 1. Process wait list.
    Collection<Collection<DelayedMessage>> delayedMsgs = new ArrayList<>();
    lock.writeLock().lock();
    try {
        started = true;
        for (Entry<UUID, Deque<DelayedMessage>> e : waitMap.entrySet()) {
            if (ctx.discovery().node(e.getKey()) != null) {
                Deque<DelayedMessage> waitList = waitMap.remove(e.getKey());
                if (log.isDebugEnabled())
                    log.debug("Processing messages from discovery startup delay list: " + waitList);
                if (waitList != null)
                    delayedMsgs.add(waitList);
            }
        }
    } finally {
        lock.writeLock().unlock();
    }
    // After write lock released.
    if (!delayedMsgs.isEmpty()) {
        for (Collection<DelayedMessage> col : delayedMsgs) for (DelayedMessage msg : col) commLsnr.onMessage(msg.nodeId(), msg.message(), msg.callback());
    }
    // 2. Process messages sets.
    for (Map.Entry<Object, ConcurrentMap<UUID, GridCommunicationMessageSet>> e : msgSetMap.entrySet()) {
        ConcurrentMap<UUID, GridCommunicationMessageSet> map = e.getValue();
        for (GridCommunicationMessageSet set : map.values()) {
            if (ctx.discovery().node(set.nodeId()) == null) {
                // All map modifications should be synced for consistency.
                boolean rmv;
                synchronized (map) {
                    rmv = map.remove(set.nodeId(), set);
                }
                if (rmv) {
                    if (log.isDebugEnabled())
                        log.debug("Removed message set due to node leaving grid: " + set);
                    // Unregister timeout listener.
                    ctx.timeout().removeTimeoutObject(set);
                }
            }
        }
        boolean rmv;
        synchronized (map) {
            rmv = map.isEmpty();
        }
        if (rmv) {
            msgSetMap.remove(e.getKey(), map);
            // Node may still send stale messages for this topic
            // even after discovery notification is done.
            closedTopics.add(e.getKey());
        }
    }
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) ConcurrentMap(java.util.concurrent.ConcurrentMap) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Deque(java.util.Deque) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Entry(java.util.Map.Entry) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Collection(java.util.Collection) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) UUID(java.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

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