Search in sources :

Example 86 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.

the class GridCacheProcessor method resetCacheState.

/**
 * Resets cache state after the cache has been moved to recovery state.
 *
 * @param cacheNames Cache names.
 * @return Future that will be completed when state is changed for all caches.
 */
public IgniteInternalFuture<?> resetCacheState(Collection<String> cacheNames) throws ClusterTopologyCheckedException {
    sharedCtx.tm().checkEmptyTransactions(() -> format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheNames, "resetCacheState"));
    Collection<DynamicCacheChangeRequest> reqs = new ArrayList<>(cacheNames.size());
    for (String cacheName : cacheNames) {
        final IgniteInternalCache<Object, Object> cache0 = internalCache(cacheName);
        if (cache0 == null)
            continue;
        // Check if all lost partitions has at least one affinity owner.
        final Collection<Integer> lostParts = cache0.lostPartitions();
        if (lostParts.isEmpty())
            continue;
        for (Integer part : lostParts) {
            final Collection<ClusterNode> owners = cache0.affinity().mapPartitionToPrimaryAndBackups(part);
            if (owners.isEmpty())
                throw new ClusterTopologyCheckedException("Cannot reset lost partitions because no baseline nodes " + "are online [cache=" + cacheName + ", partition=" + part + ']');
        }
        DynamicCacheChangeRequest req = DynamicCacheChangeRequest.resetLostPartitions(ctx, cacheName);
        reqs.add(req);
    }
    return initiateCacheChanges(reqs).stream().collect(IgniteCollectors.toCompoundFuture());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DetachedClusterNode(org.apache.ignite.internal.cluster.DetachedClusterNode) ArrayList(java.util.ArrayList) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 87 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.

the class GridCacheIoManager method send.

/**
 * Sends communication message.
 *
 * @param nodeId ID of node to send the message to.
 * @param msg Message to send.
 * @param plc IO policy.
 * @throws IgniteCheckedException If sending failed.
 */
public void send(UUID nodeId, GridCacheMessage msg, byte plc) throws IgniteCheckedException {
    ClusterNode n = cctx.discovery().node(nodeId);
    if (n == null)
        throw new ClusterTopologyCheckedException("Failed to send message because node left grid [nodeId=" + nodeId + ", msg=" + msg + ']');
    send(n, msg, plc);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 88 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.

the class CacheContinuousQueryHandler method onEntryUpdate.

/**
 * @param evt Continuous query event.
 * @param notify Notify flag.
 * @param loc Listener deployed on this node.
 * @param recordIgniteEvt Record ignite event.
 */
private void onEntryUpdate(CacheContinuousQueryEvent<K, V> evt, boolean notify, boolean loc, boolean recordIgniteEvt) {
    try {
        GridCacheContext<K, V> cctx = cacheContext(ctx);
        if (cctx == null)
            return;
        CacheContinuousQueryEntry entry = evt.entry();
        IgniteClosure<CacheEntryEvent<? extends K, ? extends V>, ?> trans = getTransformer();
        if (loc) {
            if (!locOnly) {
                Collection<CacheEntryEvent<? extends K, ? extends V>> evts = handleEvent(ctx, entry);
                notifyLocalListener(evts, trans);
                if (!internal && !skipPrimaryCheck)
                    sendBackupAcknowledge(ackBufBackup.onAcknowledged(entry), routineId, ctx);
            } else {
                if (!entry.isFiltered())
                    notifyLocalListener(F.<CacheEntryEvent<? extends K, ? extends V>>asList(evt), trans);
            }
        } else {
            if (!entry.isFiltered()) {
                if (trans != null)
                    entry = transformToEntry(trans, evt);
                prepareEntry(cctx, nodeId, entry);
            }
            Object entryOrList = handleEntry(cctx, entry);
            if (entryOrList != null) {
                if (log.isDebugEnabled())
                    log.debug("Send the following event to listener: " + entryOrList);
                ctx.continuous().addNotification(nodeId, routineId, entryOrList, topic, sync, true);
            }
        }
    } catch (ClusterTopologyCheckedException ex) {
        if (log.isDebugEnabled())
            log.debug("Failed to send event notification to node, node left cluster " + "[node=" + nodeId + ", err=" + ex + ']');
    } catch (IgniteCheckedException ex) {
        U.error(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), "Failed to send event notification to node: " + nodeId, ex);
    }
    if (recordIgniteEvt && notify) {
        CacheEntryEventFilter filter;
        try {
            filter = getEventFilter();
        } catch (IgniteCheckedException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to trigger a continuoue query event. " + "[routineId=" + routineId + ", cacheName=" + cacheName + ", err=" + e + "]");
            }
            return;
        }
        // noinspection unchecked
        ctx.event().record(new CacheQueryReadEvent<K, V>(ctx.discovery().localNode(), "Continuous query executed.", EVT_CACHE_QUERY_OBJECT_READ, CacheQueryType.CONTINUOUS.name(), cacheName, null, null, null, filter instanceof CacheEntryEventSerializableFilter ? (CacheEntryEventSerializableFilter) filter : null, null, nodeId, taskName(), evt.getKey(), evt.getValue(), evt.getOldValue(), null));
    }
}
Also used : CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) CacheEntryEvent(javax.cache.event.CacheEntryEvent) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 89 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.

the class GridEventConsumeHandler method register.

/**
 * {@inheritDoc}
 */
@Override
public RegisterStatus register(final UUID nodeId, final UUID routineId, final GridKernalContext ctx) throws IgniteCheckedException {
    assert nodeId != null;
    assert routineId != null;
    assert ctx != null;
    if (cb != null)
        ctx.resource().injectGeneric(cb);
    final boolean loc = nodeId.equals(ctx.localNodeId());
    lsnr = new GridLocalEventListener() {

        /**
         * node ID, routine ID, event
         */
        private final Queue<T3<UUID, UUID, Event>> notificationQueue = new LinkedList<>();

        private boolean notificationInProgress;

        @Override
        public void onEvent(Event evt) {
            if (filterDropsEvent(evt))
                return;
            if (loc) {
                if (!cb.apply(nodeId, evt))
                    ctx.continuous().stopRoutine(routineId);
            } else {
                if (ctx.discovery().node(nodeId) == null)
                    return;
                synchronized (notificationQueue) {
                    notificationQueue.add(new T3<>(nodeId, routineId, evt));
                    if (!notificationInProgress) {
                        ctx.pools().getSystemExecutorService().execute(new Runnable() {

                            @Override
                            public void run() {
                                if (!ctx.continuous().lockStopping())
                                    return;
                                try {
                                    while (true) {
                                        T3<UUID, UUID, Event> t3;
                                        synchronized (notificationQueue) {
                                            t3 = notificationQueue.poll();
                                            if (t3 == null) {
                                                notificationInProgress = false;
                                                return;
                                            }
                                        }
                                        try {
                                            Event evt = t3.get3();
                                            EventWrapper wrapper = new EventWrapper(evt);
                                            if (evt instanceof CacheEvent) {
                                                String cacheName = ((CacheEvent) evt).cacheName();
                                                ClusterNode node = ctx.discovery().node(t3.get1());
                                                if (node == null)
                                                    continue;
                                                if (ctx.config().isPeerClassLoadingEnabled()) {
                                                    GridCacheContext cctx = ctx.cache().internalCache(cacheName).context();
                                                    if (cctx.deploymentEnabled() && ctx.discovery().cacheNode(node, cacheName)) {
                                                        wrapper.p2pMarshal(ctx.config().getMarshaller());
                                                        wrapper.cacheName = cacheName;
                                                        cctx.deploy().prepare(wrapper);
                                                    }
                                                }
                                            }
                                            ctx.continuous().addNotification(t3.get1(), t3.get2(), wrapper, null, false, false);
                                        } catch (ClusterTopologyCheckedException ignored) {
                                        // No-op.
                                        } catch (Throwable e) {
                                            U.error(ctx.log(GridEventConsumeHandler.class), "Failed to send event notification to node: " + nodeId, e);
                                        }
                                    }
                                } finally {
                                    ctx.continuous().unlockStopping();
                                }
                            }
                        });
                        notificationInProgress = true;
                    }
                }
            }
        }
    };
    if (F.isEmpty(types))
        types = EVTS_ALL;
    p2pUnmarshalFut.listen((fut) -> {
        if (fut.error() == null) {
            try {
                initFilter(filter, ctx);
            } catch (IgniteCheckedException e) {
                throw F.wrap(e);
            }
            ctx.event().addLocalEventListener(lsnr, types);
        }
    });
    return RegisterStatus.REGISTERED;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) LinkedList(java.util.LinkedList) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheEvent(org.apache.ignite.events.CacheEvent) CacheEvent(org.apache.ignite.events.CacheEvent) Event(org.apache.ignite.events.Event) UUID(java.util.UUID) T3(org.apache.ignite.internal.util.typedef.T3) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 90 with ClusterTopologyCheckedException

use of org.apache.ignite.internal.cluster.ClusterTopologyCheckedException in project gridgain by gridgain.

the class GridJobSiblingImpl method cancel.

/**
 * {@inheritDoc}
 */
@Override
public void cancel() {
    GridTaskSessionImpl ses = ctx.session().getSession(sesId);
    Collection<ClusterNode> nodes = ses == null ? ctx.discovery().remoteNodes() : ctx.discovery().nodes(ses.getTopology());
    for (ClusterNode node : nodes) {
        if (!ctx.localNodeId().equals(node.id())) {
            try {
                ctx.io().sendToGridTopic(node, TOPIC_JOB_CANCEL, new GridJobCancelRequest(sesId, jobId), SYSTEM_POOL);
            } catch (ClusterTopologyCheckedException e) {
                IgniteLogger log = ctx.log(GridJobSiblingImpl.class);
                if (log.isDebugEnabled())
                    log.debug("Failed to send cancel request, node left [nodeId=" + node.id() + ", ses=" + ses + ']');
            } catch (IgniteCheckedException e) {
                // Avoid stack trace for left nodes.
                if (ctx.discovery().node(node.id()) != null && ctx.discovery().pingNodeNoError(node.id()))
                    U.error(ctx.log(GridJobSiblingImpl.class), "Failed to send cancel request to node " + "[nodeId=" + node.id() + ", ses=" + ses + ']', e);
            }
        }
    }
    // Cancel local jobs directly.
    ctx.job().cancelJob(sesId, jobId, false);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteLogger(org.apache.ignite.IgniteLogger) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)204 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)147 ClusterNode (org.apache.ignite.cluster.ClusterNode)114 UUID (java.util.UUID)54 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)45 Map (java.util.Map)41 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)38 HashMap (java.util.HashMap)33 ArrayList (java.util.ArrayList)32 IgniteException (org.apache.ignite.IgniteException)32 Collection (java.util.Collection)28 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)28 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)26 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)26 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)24 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)22 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)22 Nullable (org.jetbrains.annotations.Nullable)22 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)21 List (java.util.List)19