Search in sources :

Example 11 with IgniteInternalFuture

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

the class GridNearAtomicSingleUpdateFuture method waitAndRemap.

/**
     * @param remapTopVer New topology version.
     */
private void waitAndRemap(AffinityTopologyVersion remapTopVer) {
    if (topLocked) {
        CachePartialUpdateCheckedException e = new CachePartialUpdateCheckedException("Failed to update keys (retry update if possible).");
        ClusterTopologyCheckedException cause = new ClusterTopologyCheckedException("Failed to update keys, topology changed while execute atomic update inside transaction.");
        cause.retryReadyFuture(cctx.affinity().affinityReadyFuture(remapTopVer));
        e.add(Collections.singleton(cctx.toCacheKeyObject(key)), cause);
        completeFuture(null, e, null);
        return;
    }
    IgniteInternalFuture<AffinityTopologyVersion> fut = cctx.shared().exchange().affinityReadyFuture(remapTopVer);
    if (fut == null)
        fut = new GridFinishedFuture<>(remapTopVer);
    fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

        @Override
        public void apply(final IgniteInternalFuture<AffinityTopologyVersion> fut) {
            cctx.kernalContext().closure().runLocalSafe(new Runnable() {

                @Override
                public void run() {
                    mapOnTopology();
                }
            });
        }
    });
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 12 with IgniteInternalFuture

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

the class GridNearAtomicSingleUpdateFuture method mapOnTopology.

/** {@inheritDoc} */
@Override
protected void mapOnTopology() {
    AffinityTopologyVersion topVer;
    if (cache.topology().stopping()) {
        completeFuture(null, new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + cache.name()), null);
        return;
    }
    GridDhtTopologyFuture fut = cache.topology().topologyVersionFuture();
    if (fut.isDone()) {
        Throwable err = fut.validateCache(cctx, recovery, /*read*/
        false, key, null);
        if (err != null) {
            completeFuture(null, err, null);
            return;
        }
        topVer = fut.topologyVersion();
    } else {
        assert !topLocked : this;
        fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

            @Override
            public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
                cctx.kernalContext().closure().runLocalSafe(new Runnable() {

                    @Override
                    public void run() {
                        mapOnTopology();
                    }
                });
            }
        });
        return;
    }
    map(topVer);
}
Also used : GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 13 with IgniteInternalFuture

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

the class GridDhtAtomicCache method removeAllAsync0.

/**
     * Entry point for all public API remove methods.
     *
     * @param keys Keys to remove.
     * @param conflictMap Conflict map.
     * @param retval Return value required flag.
     * @param rawRetval Return {@code GridCacheReturn} instance.
     * @return Completion future.
     */
private IgniteInternalFuture removeAllAsync0(@Nullable Collection<? extends K> keys, @Nullable Map<KeyCacheObject, GridCacheVersion> conflictMap, final boolean retval, boolean rawRetval, boolean async) {
    assert ctx.updatesAllowed();
    assert keys != null || conflictMap != null;
    if (keyCheck)
        validateCacheKeys(keys);
    ctx.checkSecurity(SecurityPermission.CACHE_REMOVE);
    final CacheOperationContext opCtx = ctx.operationContextPerCall();
    UUID subjId = ctx.subjectIdPerCall(null, opCtx);
    int taskNameHash = ctx.kernalContext().job().currentTaskNameHash();
    Collection<GridCacheVersion> drVers = null;
    if (opCtx != null && keys != null && opCtx.hasDataCenterId()) {
        assert conflictMap == null : conflictMap;
        drVers = F.transform(keys, new C1<K, GridCacheVersion>() {

            @Override
            public GridCacheVersion apply(K k) {
                return ctx.versions().next(opCtx.dataCenterId());
            }
        });
    }
    final GridNearAtomicUpdateFuture updateFut = new GridNearAtomicUpdateFuture(ctx, this, ctx.config().getWriteSynchronizationMode(), DELETE, keys != null ? keys : conflictMap.keySet(), null, null, null, drVers != null ? drVers : (keys != null ? null : conflictMap.values()), retval, rawRetval, opCtx != null ? opCtx.expiry() : null, CU.filterArray(null), subjId, taskNameHash, opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary(), opCtx != null && opCtx.recovery(), opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES);
    if (async) {
        return asyncOp(new CO<IgniteInternalFuture<Object>>() {

            @Override
            public IgniteInternalFuture<Object> apply() {
                updateFut.map();
                return updateFut;
            }
        });
    } else {
        updateFut.map();
        return updateFut;
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) UUID(java.util.UUID) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) C1(org.apache.ignite.internal.util.typedef.C1)

Example 14 with IgniteInternalFuture

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

the class GridDhtAtomicCache method invoke0.

/**
     * @param async Async operation flag.
     * @param key Key.
     * @param entryProcessor Entry processor.
     * @param args Entry processor arguments.
     * @return Future.
     */
private <T> IgniteInternalFuture<EntryProcessorResult<T>> invoke0(boolean async, K key, EntryProcessor<K, V, T> entryProcessor, Object... args) {
    A.notNull(key, "key", entryProcessor, "entryProcessor");
    if (keyCheck)
        validateCacheKey(key);
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
    IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> fut = update0(key, null, entryProcessor, args, false, null, async);
    return fut.chain(new CX1<IgniteInternalFuture<Map<K, EntryProcessorResult<T>>>, EntryProcessorResult<T>>() {

        @Override
        public EntryProcessorResult<T> applyx(IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> fut) throws IgniteCheckedException {
            Map<K, EntryProcessorResult<T>> resMap = fut.get();
            if (resMap != null) {
                assert resMap.isEmpty() || resMap.size() == 1 : resMap.size();
                EntryProcessorResult<T> res = resMap.isEmpty() ? null : resMap.values().iterator().next();
                if (res instanceof CacheInvokeResult) {
                    CacheInvokeResult invokeRes = (CacheInvokeResult) res;
                    if (invokeRes.result() != null)
                        res = CacheInvokeResult.fromResult((T) ctx.unwrapBinaryIfNeeded(invokeRes.result(), keepBinary, false));
                }
                return res;
            }
            return null;
        }
    });
}
Also used : EntryProcessorResult(javax.cache.processor.EntryProcessorResult) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IGNITE_ATOMIC_DEFERRED_ACK_TIMEOUT(org.apache.ignite.IgniteSystemProperties.IGNITE_ATOMIC_DEFERRED_ACK_TIMEOUT) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) HashMap(java.util.HashMap) CacheInvokeResult(org.apache.ignite.internal.processors.cache.CacheInvokeResult)

Example 15 with IgniteInternalFuture

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

the class GridDhtAtomicCache method getAsync0.

/**
     * Entry point to all public API single get methods.
     *
     * @param key Key.
     * @param forcePrimary Force primary flag.
     * @param subjId Subject ID.
     * @param taskName Task name.
     * @param deserializeBinary Deserialize binary flag.
     * @param expiryPlc Expiry policy.
     * @param skipVals Skip values flag.
     * @param skipStore Skip store flag.
     * @param canRemap Can remap flag.
     * @param needVer Need version.
     * @return Get future.
     */
private IgniteInternalFuture<V> getAsync0(KeyCacheObject key, boolean forcePrimary, UUID subjId, String taskName, boolean deserializeBinary, boolean recovery, @Nullable ExpiryPolicy expiryPlc, boolean skipVals, boolean skipStore, boolean canRemap, boolean needVer) {
    AffinityTopologyVersion topVer = canRemap ? ctx.affinity().affinityTopologyVersion() : ctx.shared().exchange().readyAffinityVersion();
    IgniteCacheExpiryPolicy expiry = skipVals ? null : expiryPolicy(expiryPlc);
    GridPartitionedSingleGetFuture fut = new GridPartitionedSingleGetFuture(ctx, key, topVer, !skipStore, forcePrimary, subjId, taskName, deserializeBinary, expiry, skipVals, canRemap, needVer, false, recovery);
    fut.init();
    return (IgniteInternalFuture<V>) fut;
}
Also used : GridPartitionedSingleGetFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)

Aggregations

IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)178 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)88 Ignite (org.apache.ignite.Ignite)43 ArrayList (java.util.ArrayList)39 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)34 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 IgniteException (org.apache.ignite.IgniteException)23 Callable (java.util.concurrent.Callable)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)22 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)22 Map (java.util.Map)21 IgniteCache (org.apache.ignite.IgniteCache)21 HashMap (java.util.HashMap)19 UUID (java.util.UUID)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)16 CacheException (javax.cache.CacheException)14 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)14 IgniteKernal (org.apache.ignite.internal.IgniteKernal)14