Search in sources :

Example 1 with GridDhtEmbeddedFuture

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtEmbeddedFuture in project ignite by apache.

the class GridDhtColocatedCache method lockAllAsync0.

/**
 * @param cacheCtx Cache context.
 * @param tx Started colocated transaction (if any).
 * @param threadId Thread ID.
 * @param ver Lock version.
 * @param topVer Topology version.
 * @param keys Mapped keys.
 * @param txRead Tx read.
 * @param retval Return value flag.
 * @param timeout Lock timeout.
 * @param createTtl TTL for create operation.
 * @param accessTtl TTL for read operation.
 * @param filter filter Optional filter.
 * @param skipStore Skip store flag.
 * @return Lock future.
 */
private IgniteInternalFuture<Exception> lockAllAsync0(GridCacheContext<?, ?> cacheCtx, @Nullable final GridNearTxLocal tx, long threadId, final GridCacheVersion ver, AffinityTopologyVersion topVer, final Collection<KeyCacheObject> keys, final boolean txRead, boolean retval, final long timeout, final long createTtl, final long accessTtl, @Nullable final CacheEntryPredicate[] filter, boolean skipStore, boolean keepBinary) {
    int cnt = keys.size();
    if (tx == null) {
        GridDhtLockFuture fut = new GridDhtLockFuture(ctx, ctx.localNodeId(), ver, topVer, cnt, txRead, retval, timeout, tx, threadId, createTtl, accessTtl, filter, skipStore, keepBinary);
        // Add before mapping.
        if (!ctx.mvcc().addFuture(fut))
            throw new IllegalStateException("Duplicate future ID: " + fut);
        boolean timedout = false;
        for (KeyCacheObject key : keys) {
            if (timedout)
                break;
            while (true) {
                GridDhtCacheEntry entry = entryExx(key, topVer);
                try {
                    fut.addEntry(key == null ? null : entry);
                    if (fut.isDone())
                        timedout = true;
                    break;
                } catch (GridCacheEntryRemovedException ignore) {
                    if (log.isDebugEnabled())
                        log.debug("Got removed entry when adding lock (will retry): " + entry);
                } catch (GridDistributedLockCancelledException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to add entry [err=" + e + ", entry=" + entry + ']');
                    fut.onError(e);
                    return new GridDhtFinishedFuture<>(e);
                }
            }
        }
        // This will send remote messages.
        fut.map();
        return new GridDhtEmbeddedFuture<>(new C2<Boolean, Exception, Exception>() {

            @Override
            public Exception apply(Boolean b, Exception e) {
                if (e != null)
                    e = U.unwrap(e);
                else if (!b)
                    e = new GridCacheLockTimeoutException(ver);
                return e;
            }
        }, fut);
    } else {
        // Handle implicit locks for pessimistic transactions.
        ctx.tm().txContext(tx);
        if (log.isDebugEnabled())
            log.debug("Performing colocated lock [tx=" + tx + ", keys=" + keys + ']');
        IgniteInternalFuture<GridCacheReturn> txFut = tx.lockAllAsync(cacheCtx, keys, retval, txRead, createTtl, accessTtl, skipStore, keepBinary);
        return new GridDhtEmbeddedFuture<>(new C2<GridCacheReturn, Exception, Exception>() {

            @Override
            public Exception apply(GridCacheReturn ret, Exception e) {
                if (e != null)
                    e = U.unwrap(e);
                assert !tx.empty();
                return e;
            }
        }, txFut);
    }
}
Also used : GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) GridDistributedLockCancelledException(org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException) GridCacheLockTimeoutException(org.apache.ignite.internal.processors.cache.GridCacheLockTimeoutException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridCacheLockTimeoutException(org.apache.ignite.internal.processors.cache.GridCacheLockTimeoutException) GridDistributedLockCancelledException(org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) GridDhtEmbeddedFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtEmbeddedFuture) GridDhtLockFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)1 GridCacheLockTimeoutException (org.apache.ignite.internal.processors.cache.GridCacheLockTimeoutException)1 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1 GridDistributedLockCancelledException (org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockCancelledException)1 GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)1 GridDhtEmbeddedFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtEmbeddedFuture)1 GridDhtLockFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLockFuture)1 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException)1