Search in sources :

Example 6 with GridEmbeddedFuture

use of org.apache.ignite.internal.util.future.GridEmbeddedFuture in project ignite by apache.

the class GridCacheAdapter method commitTxAsync.

/**
     * Asynchronously commits transaction after all previous asynchronous operations are completed.
     *
     * @param tx Transaction to commit.
     * @return Transaction commit future.
     */
@SuppressWarnings("unchecked")
IgniteInternalFuture<IgniteInternalTx> commitTxAsync(final GridNearTxLocal tx) {
    FutureHolder holder = lastFut.get();
    holder.lock();
    try {
        IgniteInternalFuture fut = holder.future();
        if (fut != null && !fut.isDone()) {
            IgniteInternalFuture<IgniteInternalTx> f = new GridEmbeddedFuture<>(fut, new C2<Object, Exception, IgniteInternalFuture<IgniteInternalTx>>() {

                @Override
                public IgniteInternalFuture<IgniteInternalTx> apply(Object o, Exception e) {
                    return tx.commitNearTxLocalAsync();
                }
            });
            saveFuture(holder, f, /*retry*/
            false);
            return f;
        }
        IgniteInternalFuture<IgniteInternalTx> f = tx.commitNearTxLocalAsync();
        saveFuture(holder, f, /*retry*/
        false);
        ctx.tm().resetContext();
        return f;
    } finally {
        holder.unlock();
    }
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) InvalidObjectException(java.io.InvalidObjectException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IOException(java.io.IOException) ObjectStreamException(java.io.ObjectStreamException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) NoSuchElementException(java.util.NoSuchElementException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture)

Example 7 with GridEmbeddedFuture

use of org.apache.ignite.internal.util.future.GridEmbeddedFuture in project ignite by apache.

the class GridCacheAdapter method asyncOp.

/**
     * @param tx Transaction.
     * @param op Cache operation.
     * @param opCtx Cache operation context.
     * @param <T> Return type.
     * @return Future.
     */
@SuppressWarnings("unchecked")
protected <T> IgniteInternalFuture<T> asyncOp(GridNearTxLocal tx, final AsyncOp<T> op, final CacheOperationContext opCtx, final boolean retry) {
    IgniteInternalFuture<T> fail = asyncOpAcquire(retry);
    if (fail != null)
        return fail;
    FutureHolder holder = lastFut.get();
    holder.lock();
    try {
        IgniteInternalFuture fut = holder.future();
        final GridNearTxLocal tx0 = tx;
        if (fut != null && !fut.isDone()) {
            IgniteInternalFuture<T> f = new GridEmbeddedFuture(fut, new IgniteOutClosure<IgniteInternalFuture>() {

                @Override
                public IgniteInternalFuture<T> apply() {
                    if (ctx.kernalContext().isStopping())
                        return new GridFinishedFuture<>(new IgniteCheckedException("Operation has been cancelled (node is stopping)."));
                    return op.op(tx0, opCtx).chain(new CX1<IgniteInternalFuture<T>, T>() {

                        @Override
                        public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
                            try {
                                return tFut.get();
                            } catch (IgniteTxRollbackCheckedException e) {
                                throw e;
                            } catch (IgniteCheckedException e1) {
                                tx0.rollbackNearTxLocalAsync();
                                throw e1;
                            } finally {
                                ctx.shared().txContextReset();
                            }
                        }
                    });
                }
            });
            saveFuture(holder, f, retry);
            return f;
        }
        final IgniteInternalFuture<T> f = op.op(tx, opCtx).chain(new CX1<IgniteInternalFuture<T>, T>() {

            @Override
            public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
                try {
                    return tFut.get();
                } catch (IgniteTxRollbackCheckedException e) {
                    throw e;
                } catch (IgniteCheckedException e1) {
                    tx0.rollbackNearTxLocalAsync();
                    throw e1;
                } finally {
                    ctx.shared().txContextReset();
                }
            }
        });
        saveFuture(holder, f, retry);
        if (tx.implicit())
            ctx.tm().resetContext();
        return f;
    } finally {
        holder.unlock();
    }
}
Also used : GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) IGNITE_CACHE_RETRIES_COUNT(org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT) CX1(org.apache.ignite.internal.util.typedef.CX1)

Example 8 with GridEmbeddedFuture

use of org.apache.ignite.internal.util.future.GridEmbeddedFuture in project ignite by apache.

the class GridNearTxLocal method lockAllAsync.

/**
     * @param cacheCtx Cache context.
     * @param keys Keys.
     * @param retval Return value flag.
     * @param read Read flag.
     * @param createTtl Create ttl.
     * @param accessTtl Access ttl.
     * @param <K> Key type.
     * @param skipStore Skip store flag.
     * @param keepBinary Keep binary flag.
     * @return Future with respond.
     */
public <K> IgniteInternalFuture<GridCacheReturn> lockAllAsync(GridCacheContext cacheCtx, final Collection<? extends K> keys, boolean retval, boolean read, long createTtl, long accessTtl, boolean skipStore, boolean keepBinary) {
    assert pessimistic();
    try {
        checkValid();
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture<>(e);
    }
    final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
    if (F.isEmpty(keys))
        return new GridFinishedFuture<>(ret);
    init();
    if (log.isDebugEnabled())
        log.debug("Before acquiring transaction lock on keys: " + keys);
    long timeout = remainingTime();
    if (timeout == -1)
        return new GridFinishedFuture<>(timeoutException());
    IgniteInternalFuture<Boolean> fut = cacheCtx.colocated().lockAllAsyncInternal(keys, timeout, this, isInvalidate(), read, retval, isolation, createTtl, accessTtl, CU.empty0(), skipStore, keepBinary);
    return new GridEmbeddedFuture<>(fut, new PLC1<GridCacheReturn>(ret, false) {

        @Override
        protected GridCacheReturn postLock(GridCacheReturn ret) {
            if (log.isDebugEnabled())
                log.debug("Acquired transaction lock on keys: " + keys);
            return ret;
        }
    });
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 GridEmbeddedFuture (org.apache.ignite.internal.util.future.GridEmbeddedFuture)8 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)6 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)6 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 Map (java.util.Map)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)4 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)4 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)4 HashMap (java.util.HashMap)3 CacheException (javax.cache.CacheException)3 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)3 IgniteTxOptimisticCheckedException (org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)3 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)3 IOException (java.io.IOException)2 InvalidObjectException (java.io.InvalidObjectException)2 ObjectStreamException (java.io.ObjectStreamException)2 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2