Search in sources :

Example 71 with ClusterTopologyCheckedException

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

the class GridNearGetFuture method map.

/**
 * @param keys Keys.
 * @param mapped Mappings to check for duplicates.
 * @param topVer Topology version to map on.
 */
private void map(Collection<KeyCacheObject> keys, Map<ClusterNode, LinkedHashMap<KeyCacheObject, Boolean>> mapped, final AffinityTopologyVersion topVer) {
    Collection<ClusterNode> affNodes = CU.affinityNodes(cctx, topVer);
    if (affNodes.isEmpty()) {
        assert !cctx.affinityNode();
        onDone(new ClusterTopologyServerNotFoundException("Failed to map keys for near-only cache (all partition " + "nodes left the grid)."));
        return;
    }
    Map<ClusterNode, LinkedHashMap<KeyCacheObject, Boolean>> mappings = U.newHashMap(affNodes.size());
    Map<KeyCacheObject, GridNearCacheEntry> savedEntries = null;
    {
        boolean success = false;
        try {
            // Assign keys to primary nodes.
            for (KeyCacheObject key : keys) savedEntries = map(key, mappings, topVer, mapped, savedEntries);
            success = true;
        } finally {
            // Exception has been thrown, must release reserved near entries.
            if (!success) {
                GridCacheVersion obsolete = cctx.versions().next(topVer);
                if (savedEntries != null) {
                    for (GridNearCacheEntry reserved : savedEntries.values()) {
                        reserved.releaseEviction();
                        if (reserved.markObsolete(obsolete))
                            reserved.context().cache().removeEntry(reserved);
                    }
                }
            }
        }
    }
    if (isDone())
        return;
    final Map<KeyCacheObject, GridNearCacheEntry> saved = savedEntries != null ? savedEntries : Collections.<KeyCacheObject, GridNearCacheEntry>emptyMap();
    final int keysSize = keys.size();
    // Create mini futures.
    for (Map.Entry<ClusterNode, LinkedHashMap<KeyCacheObject, Boolean>> entry : mappings.entrySet()) {
        final ClusterNode n = entry.getKey();
        final LinkedHashMap<KeyCacheObject, Boolean> mappedKeys = entry.getValue();
        assert !mappedKeys.isEmpty();
        // If this is the primary or backup node for the keys.
        if (n.isLocal()) {
            final GridDhtFuture<Collection<GridCacheEntryInfo>> fut = dht().getDhtAsync(n.id(), -1, mappedKeys, false, readThrough, topVer, subjId, taskName == null ? 0 : taskName.hashCode(), expiryPlc, skipVals, recovery);
            final Collection<Integer> invalidParts = fut.invalidPartitions();
            if (!F.isEmpty(invalidParts)) {
                Collection<KeyCacheObject> remapKeys = new ArrayList<>(keysSize);
                for (KeyCacheObject key : keys) {
                    if (key != null && invalidParts.contains(cctx.affinity().partition(key)))
                        remapKeys.add(key);
                }
                AffinityTopologyVersion updTopVer = cctx.shared().exchange().readyAffinityVersion();
                assert updTopVer.compareTo(topVer) > 0 : "Got invalid partitions for local node but topology version did " + "not change [topVer=" + topVer + ", updTopVer=" + updTopVer + ", invalidParts=" + invalidParts + ']';
                // Remap recursively.
                map(remapKeys, mappings, updTopVer);
            }
            // Add new future.
            add(fut.chain(new C1<IgniteInternalFuture<Collection<GridCacheEntryInfo>>, Map<K, V>>() {

                @Override
                public Map<K, V> apply(IgniteInternalFuture<Collection<GridCacheEntryInfo>> fut) {
                    try {
                        return loadEntries(n.id(), mappedKeys.keySet(), fut.get(), saved, topVer);
                    } catch (Exception e) {
                        U.error(log, "Failed to get values from dht cache [fut=" + fut + "]", e);
                        onDone(e);
                        return Collections.emptyMap();
                    }
                }
            }));
        } else {
            if (!trackable) {
                trackable = true;
                cctx.mvcc().addFuture(this, futId);
            }
            MiniFuture fut = new MiniFuture(n, mappedKeys, saved, topVer, CU.createBackupPostProcessingClosure(topVer, log, cctx, null, expiryPlc, readThrough, skipVals));
            GridCacheMessage req = new GridNearGetRequest(cctx.cacheId(), futId, fut.futureId(), ver, mappedKeys, readThrough, topVer, subjId, taskName == null ? 0 : taskName.hashCode(), expiryPlc != null ? expiryPlc.forCreate() : -1L, expiryPlc != null ? expiryPlc.forAccess() : -1L, true, skipVals, cctx.deploymentEnabled(), recovery);
            // Append new future.
            add(fut);
            try {
                cctx.io().send(n, req, cctx.ioPolicy());
            } catch (IgniteCheckedException e) {
                // Fail the whole thing.
                if (e instanceof ClusterTopologyCheckedException)
                    fut.onNodeLeft();
                else
                    fut.onResult(e);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) C1(org.apache.ignite.internal.util.typedef.C1) LinkedHashMap(java.util.LinkedHashMap) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) Collection(java.util.Collection) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 72 with ClusterTopologyCheckedException

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

the class GridNearAtomicSingleUpdateFuture method onAllReceived.

/**
 * @return Non-null topology version if update should be remapped.
 */
private AffinityTopologyVersion onAllReceived() {
    assert Thread.holdsLock(this);
    assert futureMapped() : this;
    AffinityTopologyVersion remapTopVer0 = null;
    if (remapTopVer == null) {
        if (err != null && X.hasCause(err, CachePartialUpdateCheckedException.class) && X.hasCause(err, ClusterTopologyCheckedException.class) && storeFuture() && --remapCnt > 0) {
            ClusterTopologyCheckedException topErr = X.cause(err, ClusterTopologyCheckedException.class);
            if (!(topErr instanceof ClusterTopologyServerNotFoundException)) {
                CachePartialUpdateCheckedException cause = X.cause(err, CachePartialUpdateCheckedException.class);
                assert cause != null && cause.topologyVersion() != null : err;
                remapTopVer0 = new AffinityTopologyVersion(cause.topologyVersion().topologyVersion() + 1);
                err = null;
            }
        }
    } else
        remapTopVer0 = remapTopVer;
    if (remapTopVer0 != null) {
        cctx.mvcc().removeAtomicFuture(futId);
        reqState = null;
        topVer = AffinityTopologyVersion.ZERO;
        futId = 0;
        remapTopVer = null;
    }
    return remapTopVer0;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 73 with ClusterTopologyCheckedException

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

the class IgniteUtils method exceptionConverters.

/**
 * Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
 *
 * @return Exception converters.
 */
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
    Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
    m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
        }
    });
    m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteFutureCancelledException(e.getMessage(), e);
        }
    });
    m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteFutureTimeoutException(e.getMessage(), e);
        }
    });
    m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ClusterGroupEmptyException(e.getMessage(), e);
        }
    });
    m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
            ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
            if (checked.retryReadyFuture() != null)
                topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
            return topEx;
        }
    });
    m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteDeploymentException(e.getMessage(), e);
        }
    });
    m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ComputeTaskTimeoutException(e.getMessage(), e);
        }
    });
    m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ComputeTaskCancelledException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionRollbackException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionHeuristicException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            if (e.getCause() instanceof TransactionDeadlockException)
                return new TransactionTimeoutException(e.getMessage(), e.getCause());
            return new TransactionTimeoutException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionOptimisticException(e.getMessage(), e);
        }
    });
    m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
        }
    });
    return m;
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TransactionHeuristicException(org.apache.ignite.transactions.TransactionHeuristicException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) C1(org.apache.ignite.internal.util.typedef.C1) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) ComputeTaskCancelledException(org.apache.ignite.compute.ComputeTaskCancelledException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 74 with ClusterTopologyCheckedException

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

the class GridNearTxLocal method enlistWriteEntry.

/**
 * @param cacheCtx Cache context.
 * @param cacheKey Key.
 * @param val Value.
 * @param entryProcessor Entry processor.
 * @param invokeArgs Optional arguments for EntryProcessor.
 * @param expiryPlc Explicitly specified expiry policy for entry.
 * @param retval Return value flag.
 * @param lockOnly Lock only flag.
 * @param filter Filter.
 * @param drVer DR version.
 * @param drTtl DR ttl.
 * @param drExpireTime DR expire time.
 * @param ret Return value.
 * @param enlisted Enlisted keys collection.
 * @param skipStore Skip store flag.
 * @param singleRmv {@code True} for single remove operation.
 * @param hasFilters {@code True} if filters not empty.
 * @param needVal {@code True} if value is needed.
 * @param needReadVer {@code True} if need read entry version.
 * @return {@code True} if entry value should be loaded.
 * @throws IgniteCheckedException If failed.
 */
private boolean enlistWriteEntry(GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, final KeyCacheObject cacheKey, @Nullable final Object val, @Nullable final EntryProcessor<?, ?, ?> entryProcessor, @Nullable final Object[] invokeArgs, @Nullable final ExpiryPolicy expiryPlc, final boolean retval, final boolean lockOnly, final CacheEntryPredicate[] filter, final GridCacheVersion drVer, final long drTtl, long drExpireTime, final GridCacheReturn ret, @Nullable final Collection<KeyCacheObject> enlisted, boolean skipStore, boolean singleRmv, boolean hasFilters, final boolean needVal, boolean needReadVer, boolean keepBinary, boolean recovery) throws IgniteCheckedException {
    boolean loadMissed = false;
    final boolean rmv = val == null && entryProcessor == null;
    IgniteTxKey txKey = cacheCtx.txKey(cacheKey);
    IgniteTxEntry txEntry = entry(txKey);
    // First time access.
    if (txEntry == null) {
        while (true) {
            GridCacheEntryEx entry = entryEx(cacheCtx, txKey, entryTopVer != null ? entryTopVer : topologyVersion());
            try {
                entry.unswap(false);
                // Check if lock is being explicitly acquired by the same thread.
                if (!implicit && cctx.kernalContext().config().isCacheSanityCheckEnabled() && entry.lockedByThread(threadId, xidVer)) {
                    throw new IgniteCheckedException("Cannot access key within transaction if lock is " + "externally held [key=" + CU.value(cacheKey, cacheCtx, false) + ", entry=" + entry + ", xidVer=" + xidVer + ", threadId=" + threadId + ", locNodeId=" + cctx.localNodeId() + ']');
                }
                CacheObject old = null;
                GridCacheVersion readVer = null;
                if (optimistic() && !implicit()) {
                    try {
                        if (needReadVer) {
                            EntryGetResult res = primaryLocal(entry) ? entry.innerGetVersioned(null, this, /*metrics*/
                            retval, /*events*/
                            retval, CU.subjectId(this, cctx), entryProcessor, resolveTaskName(), null, keepBinary, null) : null;
                            if (res != null) {
                                old = res.value();
                                readVer = res.version();
                            }
                        } else {
                            old = entry.innerGet(null, this, /*read through*/
                            false, /*metrics*/
                            retval, /*events*/
                            retval, CU.subjectId(this, cctx), entryProcessor, resolveTaskName(), null, keepBinary);
                        }
                    } catch (ClusterTopologyCheckedException e) {
                        entry.context().evicts().touch(entry, topologyVersion());
                        throw e;
                    }
                } else
                    old = entry.rawGet();
                final GridCacheOperation op = lockOnly ? NOOP : rmv ? DELETE : entryProcessor != null ? TRANSFORM : old != null ? UPDATE : CREATE;
                if (old != null && hasFilters && !filter(entry.context(), cacheKey, old, filter)) {
                    ret.set(cacheCtx, old, false, keepBinary);
                    if (!readCommitted()) {
                        if (optimistic() && serializable()) {
                            txEntry = addEntry(op, old, entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary, CU.isNearEnabled(cacheCtx));
                        } else {
                            txEntry = addEntry(READ, old, null, null, entry, null, CU.empty0(), false, -1L, -1L, null, skipStore, keepBinary, CU.isNearEnabled(cacheCtx));
                        }
                        txEntry.markValid();
                        if (needReadVer) {
                            assert readVer != null;
                            txEntry.entryReadVersion(singleRmv ? SER_READ_NOT_EMPTY_VER : readVer);
                        }
                    }
                    if (readCommitted())
                        cacheCtx.evicts().touch(entry, topologyVersion());
                    // While.
                    break;
                }
                CacheObject cVal = cacheCtx.toCacheObject(val);
                if (op == CREATE || op == UPDATE)
                    cacheCtx.validateKeyAndValue(cacheKey, cVal);
                txEntry = addEntry(op, cVal, entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary, CU.isNearEnabled(cacheCtx));
                if (enlisted != null)
                    enlisted.add(cacheKey);
                if (!pessimistic() && !implicit()) {
                    txEntry.markValid();
                    if (old == null) {
                        if (needVal)
                            loadMissed = true;
                        else {
                            assert !implicit() || !transform : this;
                            assert txEntry.op() != TRANSFORM : txEntry;
                            if (retval)
                                ret.set(cacheCtx, null, true, keepBinary);
                            else
                                ret.success(true);
                        }
                    } else {
                        if (needReadVer) {
                            assert readVer != null;
                            txEntry.entryReadVersion(singleRmv ? SER_READ_NOT_EMPTY_VER : readVer);
                        }
                        if (retval && !transform)
                            ret.set(cacheCtx, old, true, keepBinary);
                        else {
                            if (txEntry.op() == TRANSFORM) {
                                GridCacheVersion ver;
                                try {
                                    ver = entry.version();
                                } catch (GridCacheEntryRemovedException ex) {
                                    assert optimistic() : txEntry;
                                    if (log.isDebugEnabled())
                                        log.debug("Failed to get entry version " + "[err=" + ex.getMessage() + ']');
                                    ver = null;
                                }
                                addInvokeResult(txEntry, old, ret, ver);
                            } else
                                ret.success(true);
                        }
                    }
                } else // Pessimistic.
                {
                    if (retval && !transform)
                        ret.set(cacheCtx, old, true, keepBinary);
                    else
                        ret.success(true);
                }
                // While.
                break;
            } catch (GridCacheEntryRemovedException ignore) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry in transaction putAll0 method: " + entry);
            }
        }
    } else {
        if (entryProcessor == null && txEntry.op() == TRANSFORM)
            throw new IgniteCheckedException("Failed to enlist write value for key (cannot have update value in " + "transaction after EntryProcessor is applied): " + CU.value(cacheKey, cacheCtx, false));
        GridCacheEntryEx entry = txEntry.cached();
        CacheObject v = txEntry.value();
        boolean del = txEntry.op() == DELETE && rmv;
        if (!del) {
            if (hasFilters && !filter(entry.context(), cacheKey, v, filter)) {
                ret.set(cacheCtx, v, false, keepBinary);
                return loadMissed;
            }
            GridCacheOperation op = rmv ? DELETE : entryProcessor != null ? TRANSFORM : v != null ? UPDATE : CREATE;
            CacheObject cVal = cacheCtx.toCacheObject(val);
            if (op == CREATE || op == UPDATE)
                cacheCtx.validateKeyAndValue(cacheKey, cVal);
            txEntry = addEntry(op, cVal, entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary, CU.isNearEnabled(cacheCtx));
            if (enlisted != null)
                enlisted.add(cacheKey);
            if (txEntry.op() == TRANSFORM) {
                GridCacheVersion ver;
                try {
                    ver = entry.version();
                } catch (GridCacheEntryRemovedException e) {
                    assert optimistic() : txEntry;
                    if (log.isDebugEnabled())
                        log.debug("Failed to get entry version: [msg=" + e.getMessage() + ']');
                    ver = null;
                }
                addInvokeResult(txEntry, txEntry.value(), ret, ver);
            }
        }
        if (!pessimistic()) {
            txEntry.markValid();
            if (retval && !transform)
                ret.set(cacheCtx, v, true, keepBinary);
            else
                ret.success(true);
        }
    }
    return loadMissed;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 75 with ClusterTopologyCheckedException

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

the class GridTaskProcessor method sendSessionAttributes.

/**
 * This method will make the best attempt to send attributes to all jobs.
 *
 * @param attrs Deserialized session attributes.
 * @param ses Task session.
 * @throws IgniteCheckedException If send to any of the jobs failed.
 */
@SuppressWarnings({ "SynchronizationOnLocalVariableOrMethodParameter", "BusyWait" })
private void sendSessionAttributes(Map<?, ?> attrs, GridTaskSessionImpl ses) throws IgniteCheckedException {
    assert attrs != null;
    assert ses != null;
    Collection<ComputeJobSibling> siblings = ses.getJobSiblings();
    GridIoManager commMgr = ctx.io();
    long timeout = ses.getEndTime() - U.currentTimeMillis();
    if (timeout <= 0) {
        U.warn(log, "Session attributes won't be set due to task timeout: " + attrs);
        return;
    }
    Set<UUID> rcvrs = new HashSet<>();
    UUID locNodeId = ctx.localNodeId();
    synchronized (ses) {
        if (ses.isClosed()) {
            if (log.isDebugEnabled())
                log.debug("Setting session attributes on closed session (will ignore): " + ses);
            return;
        }
        ses.setInternal(attrs);
        // ID will be associated with a certain session state.
        for (ComputeJobSibling s : siblings) {
            GridJobSiblingImpl sib = (GridJobSiblingImpl) s;
            UUID nodeId = sib.nodeId();
            if (!nodeId.equals(locNodeId) && !sib.isJobDone() && !rcvrs.contains(nodeId))
                rcvrs.add(nodeId);
        }
    }
    if (ctx.event().isRecordable(EVT_TASK_SESSION_ATTR_SET)) {
        Event evt = new TaskEvent(ctx.discovery().localNode(), "Changed attributes: " + attrs, EVT_TASK_SESSION_ATTR_SET, ses.getId(), ses.getTaskName(), ses.getTaskClassName(), false, null);
        ctx.event().record(evt);
    }
    IgniteCheckedException ex = null;
    // Every job gets an individual message to keep track of ghost requests.
    for (ComputeJobSibling s : ses.getJobSiblings()) {
        GridJobSiblingImpl sib = (GridJobSiblingImpl) s;
        UUID nodeId = sib.nodeId();
        // Pair can be null if job is finished.
        if (rcvrs.remove(nodeId)) {
            ClusterNode node = ctx.discovery().node(nodeId);
            // Check that node didn't change (it could happen in case of failover).
            if (node != null) {
                boolean loc = node.id().equals(ctx.localNodeId()) && !ctx.config().isMarshalLocalJobs();
                GridTaskSessionRequest req = new GridTaskSessionRequest(ses.getId(), null, loc ? null : U.marshal(marsh, attrs), attrs);
                // should be preserved here.
                try {
                    commMgr.sendOrderedMessage(node, sib.jobTopic(), req, SYSTEM_POOL, timeout, false);
                } catch (IgniteCheckedException e) {
                    node = e instanceof ClusterTopologyCheckedException ? null : ctx.discovery().node(nodeId);
                    if (node != null) {
                        try {
                            // Since communication on remote node may stop before
                            // we get discovery notification, we give ourselves the
                            // best effort to detect it.
                            Thread.sleep(DISCO_TIMEOUT);
                        } catch (InterruptedException ignore) {
                            U.warn(log, "Got interrupted while sending session attributes.");
                        }
                        node = ctx.discovery().node(nodeId);
                    }
                    String err = "Failed to send session attribute request message to node " + "(normal case if node left grid) [node=" + node + ", req=" + req + ']';
                    if (node != null)
                        U.warn(log, err);
                    else if (log.isDebugEnabled())
                        log.debug(err);
                    if (ex == null)
                        ex = e;
                }
            }
        }
    }
    if (ex != null)
        throw ex;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridJobSiblingImpl(org.apache.ignite.internal.GridJobSiblingImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) GridTaskSessionRequest(org.apache.ignite.internal.GridTaskSessionRequest) TaskEvent(org.apache.ignite.events.TaskEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) ComputeJobSibling(org.apache.ignite.compute.ComputeJobSibling) UUID(java.util.UUID) HashSet(java.util.HashSet) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)79 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 ClusterNode (org.apache.ignite.cluster.ClusterNode)49 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)19 UUID (java.util.UUID)17 Map (java.util.Map)16 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)16 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)14 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)13 HashMap (java.util.HashMap)12 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)12 ArrayList (java.util.ArrayList)11 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)10 Collection (java.util.Collection)8 IgniteException (org.apache.ignite.IgniteException)8 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)7 Event (org.apache.ignite.events.Event)6 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)6