Search in sources :

Example 36 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class TcpCommunicationSpi method dumpStats.

/**
 * Dumps SPI per-connection stats to logs.
 */
public void dumpStats() {
    final IgniteLogger log = this.diagnosticLog;
    if (log != null) {
        StringBuilder sb = new StringBuilder();
        dumpInfo(sb, null);
        U.warn(log, sb.toString());
        GridNioServer<Message> nioSrvr = this.nioSrvr;
        if (nioSrvr != null) {
            nioSrvr.dumpStats().listen(new CI1<IgniteInternalFuture<String>>() {

                @Override
                public void apply(IgniteInternalFuture<String> fut) {
                    try {
                        U.warn(log, fut.get());
                    } catch (Exception e) {
                        U.error(log, "Failed to dump NIO server statistics: " + e, e);
                    }
                }
            });
        }
    }
}
Also used : RecoveryLastReceivedMessage(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) HandshakeMessage(org.apache.ignite.spi.communication.tcp.messages.HandshakeMessage) NodeIdMessage(org.apache.ignite.spi.communication.tcp.messages.NodeIdMessage) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SSLException(javax.net.ssl.SSLException) IgniteSpiOperationTimeoutException(org.apache.ignite.spi.IgniteSpiOperationTimeoutException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ConnectException(java.net.ConnectException) IpcOutOfSystemResourcesException(org.apache.ignite.internal.util.ipc.shmem.IpcOutOfSystemResourcesException) IOException(java.io.IOException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 37 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class GridNearTxLocal method optimisticPutFuture.

/**
 * @param cacheCtx Cache context.
 * @param loadFut Missing keys load future.
 * @param ret Future result.
 * @param keepBinary Keep binary flag.
 * @return Future.
 */
private IgniteInternalFuture optimisticPutFuture(final GridCacheContext cacheCtx, IgniteInternalFuture<Void> loadFut, final GridCacheReturn ret, final boolean keepBinary) {
    if (implicit()) {
        // with prepare response, if required.
        assert loadFut.isDone();
        try {
            loadFut.get();
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(e);
        }
        return nonInterruptable(commitNearTxLocalAsync().chain(new CX1<IgniteInternalFuture<IgniteInternalTx>, GridCacheReturn>() {

            @Override
            public GridCacheReturn applyx(IgniteInternalFuture<IgniteInternalTx> txFut) throws IgniteCheckedException {
                try {
                    txFut.get();
                    Object res = implicitRes.value();
                    if (implicitRes.invokeResult()) {
                        assert res == null || res instanceof Map : implicitRes;
                        res = cacheCtx.unwrapInvokeResult((Map) res, keepBinary);
                    }
                    return new GridCacheReturn(cacheCtx, true, keepBinary, res, implicitRes.success());
                } catch (IgniteCheckedException | RuntimeException e) {
                    if (!(e instanceof NodeStoppingException))
                        rollbackNearTxLocalAsync();
                    throw e;
                }
            }
        }));
    } else {
        return nonInterruptable(loadFut.chain(new CX1<IgniteInternalFuture<Void>, GridCacheReturn>() {

            @Override
            public GridCacheReturn applyx(IgniteInternalFuture<Void> f) throws IgniteCheckedException {
                f.get();
                return ret;
            }
        }));
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CX1(org.apache.ignite.internal.util.typedef.CX1) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap)

Example 38 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class GridNearTxLocal method loadMissing.

/**
 * @param cacheCtx  Cache context.
 * @param readThrough Read through flag.
 * @param async if {@code True}, then loading will happen in a separate thread.
 * @param keys Keys.
 * @param skipVals Skip values flag.
 * @param needVer If {@code true} version is required for loaded values.
 * @param c Closure to be applied for loaded values.
 * @param expiryPlc Expiry policy.
 * @return Future with {@code True} value if loading took place.
 */
public IgniteInternalFuture<Void> loadMissing(final GridCacheContext cacheCtx, AffinityTopologyVersion topVer, boolean readThrough, boolean async, final Collection<KeyCacheObject> keys, final boolean skipVals, final boolean needVer, boolean keepBinary, boolean recovery, final ExpiryPolicy expiryPlc, final GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c) {
    IgniteCacheExpiryPolicy expiryPlc0 = optimistic() ? accessPolicy(cacheCtx, keys) : cacheCtx.cache().expiryPolicy(expiryPlc);
    if (cacheCtx.isNear()) {
        return cacheCtx.nearTx().txLoadAsync(this, topVer, keys, readThrough, /*deserializeBinary*/
        false, recovery, expiryPlc0, skipVals, needVer).chain(new C1<IgniteInternalFuture<Map<Object, Object>>, Void>() {

            @Override
            public Void apply(IgniteInternalFuture<Map<Object, Object>> f) {
                try {
                    Map<Object, Object> map = f.get();
                    processLoaded(map, keys, needVer, c);
                    return null;
                } catch (Exception e) {
                    setRollbackOnly();
                    throw new GridClosureException(e);
                }
            }
        });
    } else if (cacheCtx.isColocated()) {
        if (keys.size() == 1) {
            final KeyCacheObject key = F.first(keys);
            return cacheCtx.colocated().loadAsync(key, readThrough, /*force primary*/
            needVer || !cacheCtx.config().isReadFromBackup(), topVer, CU.subjectId(this, cctx), resolveTaskName(), /*deserializeBinary*/
            false, expiryPlc0, skipVals, needVer, /*keepCacheObject*/
            true, recovery).chain(new C1<IgniteInternalFuture<Object>, Void>() {

                @Override
                public Void apply(IgniteInternalFuture<Object> f) {
                    try {
                        Object val = f.get();
                        processLoaded(key, val, needVer, skipVals, c);
                        return null;
                    } catch (Exception e) {
                        setRollbackOnly();
                        throw new GridClosureException(e);
                    }
                }
            });
        } else {
            return cacheCtx.colocated().loadAsync(keys, readThrough, /*force primary*/
            needVer || !cacheCtx.config().isReadFromBackup(), topVer, CU.subjectId(this, cctx), resolveTaskName(), /*deserializeBinary*/
            false, recovery, expiryPlc0, skipVals, needVer, /*keepCacheObject*/
            true).chain(new C1<IgniteInternalFuture<Map<Object, Object>>, Void>() {

                @Override
                public Void apply(IgniteInternalFuture<Map<Object, Object>> f) {
                    try {
                        Map<Object, Object> map = f.get();
                        processLoaded(map, keys, needVer, c);
                        return null;
                    } catch (Exception e) {
                        setRollbackOnly();
                        throw new GridClosureException(e);
                    }
                }
            });
        }
    } else {
        assert cacheCtx.isLocal();
        return localCacheLoadMissing(cacheCtx, topVer, readThrough, async, keys, skipVals, needVer, keepBinary, recovery, expiryPlc, c);
    }
}
Also used : GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) CacheException(javax.cache.CacheException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) C1(org.apache.ignite.internal.util.typedef.C1) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 39 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class GridNearTxLocal method removeAllAsync0.

/**
 * @param cacheCtx Cache context.
 * @param keys Keys to remove.
 * @param drMap DR map.
 * @param retval Flag indicating whether a value should be returned.
 * @param filter Filter.
 * @param singleRmv {@code True} for single key remove operation ({@link Cache#remove(Object)}.
 * @return Future for asynchronous remove.
 */
@SuppressWarnings("unchecked")
private <K, V> IgniteInternalFuture<GridCacheReturn> removeAllAsync0(final GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, @Nullable final Collection<? extends K> keys, @Nullable Map<KeyCacheObject, GridCacheVersion> drMap, final boolean retval, @Nullable final CacheEntryPredicate filter, boolean singleRmv) {
    try {
        checkUpdatesAllowed(cacheCtx);
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture(e);
    }
    cacheCtx.checkSecurity(SecurityPermission.CACHE_REMOVE);
    if (retval)
        needReturnValue(true);
    final Collection<?> keys0;
    if (drMap != null) {
        assert keys == null;
        keys0 = drMap.keySet();
    } else
        keys0 = keys;
    CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
    final Byte dataCenterId;
    if (opCtx != null && opCtx.hasDataCenterId()) {
        assert drMap == null : drMap;
        dataCenterId = opCtx.dataCenterId();
    } else
        dataCenterId = null;
    assert keys0 != null;
    if (log.isDebugEnabled())
        log.debug(S.toString("Called removeAllAsync(...)", "tx", this, false, "keys", keys0, true, "implicit", implicit, false, "retval", retval, false));
    try {
        checkValid();
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture<>(e);
    }
    final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
    if (F.isEmpty(keys0)) {
        if (implicit()) {
            try {
                commit();
            } catch (IgniteCheckedException e) {
                return new GridFinishedFuture<>(e);
            }
        }
        return new GridFinishedFuture<>(ret.success(true));
    }
    init();
    final Collection<KeyCacheObject> enlisted = new ArrayList<>();
    ExpiryPolicy plc;
    final CacheEntryPredicate[] filters = CU.filterArray(filter);
    if (!F.isEmpty(filters))
        plc = opCtx != null ? opCtx.expiry() : null;
    else
        plc = null;
    final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
    final IgniteInternalFuture<Void> loadFut = enlistWrite(cacheCtx, entryTopVer, keys0, plc, /*lookup map*/
    null, /*invoke map*/
    null, /*invoke arguments*/
    null, retval, /*lock only*/
    false, filters, ret, enlisted, null, drMap, opCtx != null && opCtx.skipStore(), singleRmv, keepBinary, opCtx != null && opCtx.recovery(), dataCenterId);
    if (log.isDebugEnabled())
        log.debug("Remove keys: " + enlisted);
    // to be rolled back.
    if (pessimistic()) {
        assert loadFut == null || loadFut.isDone() : loadFut;
        if (loadFut != null) {
            try {
                loadFut.get();
            } catch (IgniteCheckedException e) {
                return new GridFinishedFuture<>(e);
            }
        }
        if (log.isDebugEnabled())
            log.debug("Before acquiring transaction lock for remove on keys: " + enlisted);
        long timeout = remainingTime();
        if (timeout == -1)
            return new GridFinishedFuture<>(timeoutException());
        IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, false, retval, isolation, isInvalidate(), -1L, -1L);
        PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {

            @Override
            protected GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
                if (log.isDebugEnabled())
                    log.debug("Acquired transaction lock for remove on keys: " + enlisted);
                postLockWrite(cacheCtx, enlisted, ret, /*remove*/
                true, retval, /*read*/
                false, -1L, filters, /*computeInvoke*/
                false);
                return ret;
            }
        };
        if (fut.isDone()) {
            try {
                return nonInterruptable(plc1.apply(fut.get(), null));
            } catch (GridClosureException e) {
                return new GridFinishedFuture<>(e.unwrap());
            } catch (IgniteCheckedException e) {
                try {
                    return nonInterruptable(plc1.apply(false, e));
                } catch (Exception e1) {
                    return new GridFinishedFuture<>(e1);
                }
            }
        } else
            return nonInterruptable(new GridEmbeddedFuture<>(fut, plc1));
    } else {
        if (implicit()) {
            // with prepare response, if required.
            assert loadFut.isDone();
            return nonInterruptable(commitNearTxLocalAsync().chain(new CX1<IgniteInternalFuture<IgniteInternalTx>, GridCacheReturn>() {

                @Override
                public GridCacheReturn applyx(IgniteInternalFuture<IgniteInternalTx> txFut) throws IgniteCheckedException {
                    try {
                        txFut.get();
                        return new GridCacheReturn(cacheCtx, true, keepBinary, implicitRes.value(), implicitRes.success());
                    } catch (IgniteCheckedException | RuntimeException e) {
                        rollbackNearTxLocalAsync();
                        throw e;
                    }
                }
            }));
        } else {
            return nonInterruptable(loadFut.chain(new CX1<IgniteInternalFuture<Void>, GridCacheReturn>() {

                @Override
                public GridCacheReturn applyx(IgniteInternalFuture<Void> f) throws IgniteCheckedException {
                    f.get();
                    return ret;
                }
            }));
        }
    }
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) CX1(org.apache.ignite.internal.util.typedef.CX1) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) CacheException(javax.cache.CacheException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate)

Example 40 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class GridNearTxLocal method commitAsyncLocal.

/**
 * Commits local part of colocated transaction.
 *
 * @return Commit future.
 */
public IgniteInternalFuture<IgniteInternalTx> commitAsyncLocal() {
    if (log.isDebugEnabled())
        log.debug("Committing colocated tx locally: " + this);
    IgniteInternalFuture<?> prep = prepFut;
    // Do not create finish future if there are no remote nodes.
    if (F.isEmpty(dhtMap) && F.isEmpty(nearMap)) {
        if (prep != null)
            return (IgniteInternalFuture<IgniteInternalTx>) prep;
        return new GridFinishedFuture<IgniteInternalTx>(this);
    }
    final GridDhtTxFinishFuture fut = new GridDhtTxFinishFuture<>(cctx, this, true);
    cctx.mvcc().addFuture(fut, fut.futureId());
    if (prep == null || prep.isDone()) {
        assert prep != null || optimistic();
        IgniteCheckedException err = null;
        try {
            if (prep != null)
                // Check for errors of a parent future.
                prep.get();
        } catch (IgniteCheckedException e) {
            err = e;
            U.error(log, "Failed to prepare transaction: " + this, e);
        }
        if (err != null)
            fut.rollbackOnError(err);
        else
            fut.finish(true);
    } else
        prep.listen(new CI1<IgniteInternalFuture<?>>() {

            @Override
            public void apply(IgniteInternalFuture<?> f) {
                IgniteCheckedException err = null;
                try {
                    // Check for errors of a parent future.
                    f.get();
                } catch (IgniteCheckedException e) {
                    err = e;
                    U.error(log, "Failed to prepare transaction: " + this, e);
                }
                if (err != null)
                    fut.rollbackOnError(err);
                else
                    fut.finish(true);
            }
        });
    return fut;
}
Also used : GridDhtTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) CI1(org.apache.ignite.internal.util.typedef.CI1) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Aggregations

IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)245 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)114 Ignite (org.apache.ignite.Ignite)71 ArrayList (java.util.ArrayList)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)46 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)46 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)43 IgniteException (org.apache.ignite.IgniteException)33 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)29 UUID (java.util.UUID)28 IgniteCache (org.apache.ignite.IgniteCache)28 ClusterNode (org.apache.ignite.cluster.ClusterNode)28 Callable (java.util.concurrent.Callable)27 HashMap (java.util.HashMap)25 Map (java.util.Map)25 CountDownLatch (java.util.concurrent.CountDownLatch)24 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)19 CacheException (javax.cache.CacheException)16 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)16 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)16