Search in sources :

Example 21 with GridLocalEventListener

use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.

the class GridMarshallerMappingProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    GridDiscoveryManager discoMgr = ctx.discovery();
    GridIoManager ioMgr = ctx.io();
    MarshallerMappingTransport transport = new MarshallerMappingTransport(ctx, mappingExchangeSyncMap, clientReqSyncMap);
    marshallerCtx.onMarshallerProcessorStarted(ctx, transport);
    discoMgr.setCustomEventListener(MappingProposedMessage.class, new MarshallerMappingExchangeListener());
    discoMgr.setCustomEventListener(MappingAcceptedMessage.class, new MappingAcceptedListener());
    if (ctx.clientNode())
        ioMgr.addMessageListener(TOPIC_MAPPING_MARSH, new MissingMappingResponseListener());
    else
        ioMgr.addMessageListener(TOPIC_MAPPING_MARSH, new MissingMappingRequestListener(ioMgr));
    if (ctx.clientNode())
        ctx.event().addLocalEventListener(new GridLocalEventListener() {

            @Override
            public void onEvent(Event evt) {
                DiscoveryEvent evt0 = (DiscoveryEvent) evt;
                if (!ctx.isStopping()) {
                    for (ClientRequestFuture fut : clientReqSyncMap.values()) fut.onNodeLeft(evt0.eventNode().id());
                }
            }
        }, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
Also used : GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 22 with GridLocalEventListener

use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.

the class AdaptiveLoadBalancingSpi method onContextInitialized0.

/** {@inheritDoc} */
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
    getSpiContext().addLocalEventListener(evtLsnr = new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            switch(evt.type()) {
                case EVT_TASK_FINISHED:
                case EVT_TASK_FAILED:
                    {
                        TaskEvent taskEvt = (TaskEvent) evt;
                        taskTops.remove(taskEvt.taskSessionId());
                        if (log.isDebugEnabled())
                            log.debug("Removed task topology from topology cache for session: " + taskEvt.taskSessionId());
                        break;
                    }
                case EVT_JOB_MAPPED:
                    {
                        // We should keep topology and use cache in ComputeTask#map() method to
                        // avoid O(n*n/2) complexity, after that we can drop caches.
                        // Here we set mapped property and later cache will be ignored
                        JobEvent jobEvt = (JobEvent) evt;
                        IgniteBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(jobEvt.taskSessionId());
                        if (weightedTop != null)
                            weightedTop.set1(true);
                        if (log.isDebugEnabled())
                            log.debug("Job has been mapped. Ignore cache for session: " + jobEvt.taskSessionId());
                        break;
                    }
                case EVT_NODE_METRICS_UPDATED:
                case EVT_NODE_FAILED:
                case EVT_NODE_JOINED:
                case EVT_NODE_LEFT:
                    {
                        DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
                        rwLock.writeLock().lock();
                        try {
                            switch(evt.type()) {
                                case EVT_NODE_JOINED:
                                    {
                                        nodeJobs.put(discoEvt.eventNode().id(), new AtomicInteger(0));
                                        break;
                                    }
                                case EVT_NODE_LEFT:
                                case EVT_NODE_FAILED:
                                    {
                                        nodeJobs.remove(discoEvt.eventNode().id());
                                        break;
                                    }
                                case EVT_NODE_METRICS_UPDATED:
                                    {
                                        // Reset counter.
                                        nodeJobs.put(discoEvt.eventNode().id(), new AtomicInteger(0));
                                        break;
                                    }
                            }
                        } finally {
                            rwLock.writeLock().unlock();
                        }
                    }
            }
        }
    }, EVT_NODE_METRICS_UPDATED, EVT_NODE_FAILED, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_TASK_FINISHED, EVT_TASK_FAILED, EVT_JOB_MAPPED);
    // Put all known nodes.
    rwLock.writeLock().lock();
    try {
        for (ClusterNode node : getSpiContext().nodes()) nodeJobs.put(node.id(), new AtomicInteger(0));
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) JobEvent(org.apache.ignite.events.JobEvent) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TaskEvent(org.apache.ignite.events.TaskEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) JobEvent(org.apache.ignite.events.JobEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent)

Example 23 with GridLocalEventListener

use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.

the class RoundRobinGlobalLoadBalancer method onContextInitialized.

/**
     * @param ctx Load balancing context.
     */
void onContextInitialized(final IgniteSpiContext ctx) {
    this.ctx = ctx;
    ctx.addLocalEventListener(lsnr = new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt instanceof DiscoveryEvent;
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            synchronized (mux) {
                if (evt.type() == EVT_NODE_JOINED) {
                    List<UUID> oldNodes = nodeList.getNodes();
                    if (!oldNodes.contains(nodeId)) {
                        List<UUID> newNodes = new ArrayList<>(oldNodes.size() + 1);
                        newNodes.add(nodeId);
                        for (UUID node : oldNodes) newNodes.add(node);
                        nodeList = new GridNodeList(0, newNodes);
                    }
                } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                    Collection<ClusterNode> nodes = ((DiscoveryEvent) evt).topologyNodes();
                    List<UUID> newNodes = new ArrayList<>(nodes.size());
                    for (ClusterNode node : nodes) newNodes.add(node.id());
                    nodeList = new GridNodeList(0, newNodes);
                } else {
                    assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED;
                    List<UUID> oldNodes = nodeList.getNodes();
                    if (oldNodes.contains(nodeId)) {
                        List<UUID> newNodes = new ArrayList<>(oldNodes.size() - 1);
                        for (UUID node : oldNodes) if (!nodeId.equals(node))
                            newNodes.add(node);
                        nodeList = new GridNodeList(0, newNodes);
                    }
                }
            }
        }
    }, EVT_NODE_FAILED, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_CLIENT_NODE_RECONNECTED);
    synchronized (mux) {
        List<UUID> oldNodes = nodeList.getNodes();
        Collection<UUID> set = oldNodes == null ? new HashSet<UUID>() : new HashSet<>(oldNodes);
        for (ClusterNode node : ctx.nodes()) set.add(node.id());
        nodeList = new GridNodeList(0, new ArrayList<>(set));
    }
    initLatch.countDown();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Example 24 with GridLocalEventListener

use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.

the class IgniteTxManager method start0.

/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
    txFinishSync = new GridCacheTxFinishSync<>(cctx);
    txHnd = new IgniteTxHandler(cctx);
    deferredAckMsgSnd = new GridDeferredAckMessageSender<GridCacheVersion>(cctx.time(), cctx.kernalContext().closure()) {

        @Override
        public int getTimeout() {
            return DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_TIMEOUT;
        }

        @Override
        public int getBufferSize() {
            return DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_BUFFER_SIZE;
        }

        @Override
        public void finish(UUID nodeId, ConcurrentLinkedDeque8<GridCacheVersion> vers) {
            GridDhtTxOnePhaseCommitAckRequest ackReq = new GridDhtTxOnePhaseCommitAckRequest(vers);
            cctx.kernalContext().gateway().readLock();
            try {
                cctx.io().send(nodeId, ackReq, GridIoPolicy.SYSTEM_POOL);
            } catch (ClusterTopologyCheckedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Failed to send one phase commit ack to backup node because it left grid: " + nodeId);
            } catch (IgniteCheckedException e) {
                log.error("Failed to send one phase commit ack to backup node [backup=" + nodeId + ']', e);
            } finally {
                cctx.kernalContext().gateway().readUnlock();
            }
        }
    };
    cctx.gridEvents().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt instanceof DiscoveryEvent;
            assert evt.type() == EVT_NODE_FAILED || evt.type() == EVT_NODE_LEFT;
            DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
            UUID nodeId = discoEvt.eventNode().id();
            // Wait some time in case there are some unprocessed messages from failed node.
            cctx.time().addTimeoutObject(new NodeFailureTimeoutObject(nodeId));
            if (txFinishSync != null)
                txFinishSync.onNodeLeft(nodeId);
            for (TxDeadlockFuture fut : deadlockDetectFuts.values()) fut.onNodeLeft(nodeId);
            for (Map.Entry<GridCacheVersion, Object> entry : completedVersHashMap.entrySet()) {
                Object obj = entry.getValue();
                if (obj instanceof GridCacheReturnCompletableWrapper && nodeId.equals(((GridCacheReturnCompletableWrapper) obj).nodeId()))
                    removeTxReturn(entry.getKey());
            }
        }
    }, EVT_NODE_FAILED, EVT_NODE_LEFT);
    this.txDeadlockDetection = new TxDeadlockDetection(cctx);
    cctx.gridIO().addMessageListener(TOPIC_TX, new DeadlockDetectionListener());
}
Also used : GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtTxOnePhaseCommitAckRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxOnePhaseCommitAckRequest) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID) GridCacheReturnCompletableWrapper(org.apache.ignite.internal.processors.cache.GridCacheReturnCompletableWrapper) TxDeadlockFuture(org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 25 with GridLocalEventListener

use of org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener in project ignite by apache.

the class IgfsFragmentizerManager method start0.

/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
    if (!igfsCtx.configuration().isFragmentizerEnabled())
        return;
    // We care only about node leave and fail events.
    igfsCtx.kernalContext().event().addLocalEventListener(new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED;
            DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
            checkLaunchCoordinator(discoEvt);
        }
    }, EVT_NODE_LEFT, EVT_NODE_FAILED);
    fragmentizerWorker = new FragmentizerWorker();
    String igfsName = igfsCtx.configuration().getName();
    topic = F.isEmpty(igfsName) ? TOPIC_IGFS : TOPIC_IGFS.topic(igfsName);
    igfsCtx.kernalContext().io().addMessageListener(topic, fragmentizerWorker);
    new IgniteThread(fragmentizerWorker).start();
}
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) IgniteThread(org.apache.ignite.thread.IgniteThread)

Aggregations

GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)26 Event (org.apache.ignite.events.Event)25 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)22 UUID (java.util.UUID)17 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Collection (java.util.Collection)5 Map (java.util.Map)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)4 HashMap (java.util.HashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 JobEvent (org.apache.ignite.events.JobEvent)3 TaskEvent (org.apache.ignite.events.TaskEvent)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Condition (java.util.concurrent.locks.Condition)2