Search in sources :

Example 6 with GridCacheReturn

use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.

the class GridNearAtomicSingleUpdateFuture method checkDhtNodes.

/**
     * @param futId Future ID.
     */
private void checkDhtNodes(long futId) {
    GridCacheReturn opRes0 = null;
    CachePartialUpdateCheckedException err0 = null;
    AffinityTopologyVersion remapTopVer0 = null;
    GridNearAtomicCheckUpdateRequest checkReq = null;
    synchronized (this) {
        if (!checkFutureId(futId))
            return;
        assert reqState != null;
        DhtLeftResult res = reqState.checkDhtNodes(cctx);
        if (res == DhtLeftResult.DONE) {
            opRes0 = opRes;
            err0 = err;
            remapTopVer0 = onAllReceived();
        } else if (res == DhtLeftResult.ALL_RCVD_CHECK_PRIMARY)
            checkReq = new GridNearAtomicCheckUpdateRequest(reqState.req);
        else
            return;
    }
    if (checkReq != null)
        sendCheckUpdateRequest(checkReq);
    else
        finishUpdateFuture(opRes0, err0, remapTopVer0, futId);
}
Also used : GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)

Example 7 with GridCacheReturn

use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.

the class GridNearAtomicSingleUpdateFuture method onDhtResponse.

/** {@inheritDoc} */
@Override
public void onDhtResponse(UUID nodeId, GridDhtAtomicNearResponse res) {
    GridCacheReturn opRes0;
    CachePartialUpdateCheckedException err0;
    AffinityTopologyVersion remapTopVer0;
    synchronized (this) {
        if (!checkFutureId(res.futureId()))
            return;
        assert reqState != null;
        assert reqState.req.nodeId().equals(res.primaryId());
        if (opRes == null && res.hasResult())
            opRes = res.result();
        if (reqState.onDhtResponse(nodeId, res)) {
            opRes0 = opRes;
            err0 = err;
            remapTopVer0 = onAllReceived();
        } else
            return;
    }
    UpdateErrors errors = res.errors();
    if (errors != null) {
        assert errors.error() != null;
        completeFuture(null, errors.error(), res.futureId());
        return;
    }
    finishUpdateFuture(opRes0, err0, remapTopVer0, res.futureId());
}
Also used : GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)

Example 8 with GridCacheReturn

use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.

the class GridNearAtomicUpdateFuture method onPrimaryResponse.

/** {@inheritDoc} */
@SuppressWarnings({ "unchecked", "ThrowableResultOfMethodCallIgnored" })
@Override
public void onPrimaryResponse(UUID nodeId, GridNearAtomicUpdateResponse res, boolean nodeErr) {
    GridNearAtomicAbstractUpdateRequest req;
    AffinityTopologyVersion remapTopVer0 = null;
    GridCacheReturn opRes0 = null;
    CachePartialUpdateCheckedException err0 = null;
    boolean rcvAll;
    synchronized (this) {
        if (!checkFutureId(res.futureId()))
            return;
        if (singleReq != null) {
            req = singleReq.processPrimaryResponse(nodeId, res);
            if (req == null)
                return;
            rcvAll = singleReq.onPrimaryResponse(res, cctx);
        } else {
            if (mappings == null)
                return;
            PrimaryRequestState reqState = mappings.get(nodeId);
            if (reqState == null)
                return;
            req = reqState.processPrimaryResponse(nodeId, res);
            if (req != null) {
                if (reqState.onPrimaryResponse(res, cctx)) {
                    assert mappings.size() > resCnt : "[mappings=" + mappings.size() + ", cnt=" + resCnt + ']';
                    resCnt++;
                    rcvAll = mappings.size() == resCnt;
                } else {
                    assert mappings.size() > resCnt : "[mappings=" + mappings.size() + ", cnt=" + resCnt + ']';
                    rcvAll = false;
                }
            } else
                return;
        }
        assert req.topologyVersion().equals(topVer) : req;
        if (res.remapTopologyVersion() != null) {
            assert !req.topologyVersion().equals(res.remapTopologyVersion());
            if (remapKeys == null)
                remapKeys = U.newHashSet(req.size());
            remapKeys.addAll(req.keys());
            if (remapTopVer == null || remapTopVer.compareTo(res.remapTopologyVersion()) < 0)
                remapTopVer = req.topologyVersion();
        } else if (res.error() != null)
            onPrimaryError(req, res);
        else {
            GridCacheReturn ret = res.returnValue();
            if (op == TRANSFORM) {
                if (ret != null) {
                    assert ret.value() == null || ret.value() instanceof Map : ret.value();
                    if (ret.value() != null) {
                        if (opRes != null)
                            opRes.mergeEntryProcessResults(ret);
                        else
                            opRes = ret;
                    }
                }
            } else
                opRes = ret;
        }
        if (rcvAll) {
            remapTopVer0 = onAllReceived();
            if (remapTopVer0 == null) {
                err0 = err;
                opRes0 = opRes;
            }
        }
    }
    if (res.error() != null && res.failedKeys() == null) {
        completeFuture(null, res.error(), res.futureId());
        return;
    }
    if (rcvAll && nearEnabled) {
        if (mappings != null) {
            for (PrimaryRequestState reqState : mappings.values()) {
                GridNearAtomicUpdateResponse res0 = reqState.req.response();
                assert res0 != null : reqState;
                updateNear(reqState.req, res0);
            }
        } else if (!nodeErr)
            updateNear(req, res);
    }
    if (remapTopVer0 != null) {
        waitAndRemap(remapTopVer0);
        return;
    }
    if (rcvAll)
        completeFuture(opRes0, err0, res.futureId());
}
Also used : GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) Map(java.util.Map)

Example 9 with GridCacheReturn

use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.

the class GridNearTxLocal method putAllAsync0.

/**
     * Internal method for all put and transform operations. Only one of {@code map}, {@code transformMap}
     * maps must be non-null.
     *
     * @param cacheCtx Context.
     * @param map Key-value map to store.
     * @param invokeMap Invoke map.
     * @param invokeArgs Optional arguments for EntryProcessor.
     * @param drMap DR map.
     * @param retval Key-transform value map to store.
     * @return Operation future.
     */
@SuppressWarnings("unchecked")
private <K, V> IgniteInternalFuture putAllAsync0(final GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, @Nullable Map<? extends K, ? extends V> map, @Nullable Map<? extends K, ? extends EntryProcessor<K, V, Object>> invokeMap, @Nullable final Object[] invokeArgs, @Nullable Map<KeyCacheObject, GridCacheDrInfo> drMap, final boolean retval) {
    try {
        beforePut(cacheCtx, retval);
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture(e);
    }
    final CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
    final Byte dataCenterId;
    if (opCtx != null && opCtx.hasDataCenterId()) {
        assert drMap == null : drMap;
        assert map != null || invokeMap != null;
        dataCenterId = opCtx.dataCenterId();
    } else
        dataCenterId = null;
    // Cached entry may be passed only from entry wrapper.
    final Map<?, ?> map0 = map;
    final Map<?, EntryProcessor<K, V, Object>> invokeMap0 = (Map<K, EntryProcessor<K, V, Object>>) invokeMap;
    if (log.isDebugEnabled())
        log.debug("Called putAllAsync(...) [tx=" + this + ", map=" + map0 + ", retval=" + retval + "]");
    assert map0 != null || invokeMap0 != null;
    final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
    if (F.isEmpty(map0) && F.isEmpty(invokeMap0)) {
        if (implicit())
            try {
                commit();
            } catch (IgniteCheckedException e) {
                return new GridFinishedFuture<>(e);
            }
        return new GridFinishedFuture<>(ret.success(true));
    }
    try {
        Set<?> keySet = map0 != null ? map0.keySet() : invokeMap0.keySet();
        final Collection<KeyCacheObject> enlisted = new ArrayList<>(keySet.size());
        final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
        final IgniteInternalFuture<Void> loadFut = enlistWrite(cacheCtx, entryTopVer, keySet, opCtx != null ? opCtx.expiry() : null, map0, invokeMap0, invokeArgs, retval, false, CU.filterArray(null), ret, enlisted, drMap, null, opCtx != null && opCtx.skipStore(), false, keepBinary, opCtx != null && opCtx.recovery(), dataCenterId);
        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 put on keys: " + enlisted);
            long timeout = remainingTime();
            if (timeout == -1)
                return new GridFinishedFuture<>(timeoutException());
            IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, // Needed to force load from store.
            invokeMap != null, /*read*/
            retval, isolation, isInvalidate(), -1L, -1L);
            PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {

                @Override
                public GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
                    if (log.isDebugEnabled())
                        log.debug("Acquired transaction lock for put on keys: " + enlisted);
                    postLockWrite(cacheCtx, enlisted, ret, /*remove*/
                    false, retval, /*read*/
                    false, -1L, CU.filterArray(null), /*computeInvoke*/
                    true);
                    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
            return optimisticPutFuture(cacheCtx, loadFut, ret, keepBinary);
    } catch (RuntimeException e) {
        onException();
        throw e;
    }
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) ArrayList(java.util.ArrayList) ROLLING_BACK(org.apache.ignite.transactions.TransactionState.ROLLING_BACK) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) 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) EntryProcessor(javax.cache.processor.EntryProcessor) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap)

Example 10 with GridCacheReturn

use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.

the class GridNearTxLocal method putAsync0.

/**
     * Internal method for single update operation.
     *
     * @param cacheCtx Cache context.
     * @param key Key.
     * @param val Value.
     * @param entryProcessor Entry processor.
     * @param invokeArgs Optional arguments for EntryProcessor.
     * @param retval Return value flag.
     * @param filter Filter.
     * @return Operation future.
     */
private <K, V> IgniteInternalFuture putAsync0(final GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, K key, @Nullable V val, @Nullable EntryProcessor<K, V, Object> entryProcessor, @Nullable final Object[] invokeArgs, final boolean retval, @Nullable final CacheEntryPredicate filter) {
    assert key != null;
    try {
        beforePut(cacheCtx, retval);
        final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
        CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
        final Byte dataCenterId = opCtx != null ? opCtx.dataCenterId() : null;
        KeyCacheObject cacheKey = cacheCtx.toCacheKeyObject(key);
        boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
        final CacheEntryPredicate[] filters = CU.filterArray(filter);
        final IgniteInternalFuture<Void> loadFut = enlistWrite(cacheCtx, entryTopVer, cacheKey, val, opCtx != null ? opCtx.expiry() : null, entryProcessor, invokeArgs, retval, /*lockOnly*/
        false, filters, ret, opCtx != null && opCtx.skipStore(), /*singleRmv*/
        false, keepBinary, opCtx != null && opCtx.recovery(), dataCenterId);
        if (pessimistic()) {
            assert loadFut == null || loadFut.isDone() : loadFut;
            if (loadFut != null)
                loadFut.get();
            final Collection<KeyCacheObject> enlisted = Collections.singleton(cacheKey);
            if (log.isDebugEnabled())
                log.debug("Before acquiring transaction lock for put on key: " + enlisted);
            long timeout = remainingTime();
            if (timeout == -1)
                return new GridFinishedFuture<>(timeoutException());
            IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, // Needed to force load from store.
            entryProcessor != null, /*read*/
            retval, isolation, isInvalidate(), -1L, -1L);
            PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {

                @Override
                public GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
                    if (log.isDebugEnabled())
                        log.debug("Acquired transaction lock for put on keys: " + enlisted);
                    postLockWrite(cacheCtx, enlisted, ret, /*remove*/
                    false, retval, /*read*/
                    false, -1L, filters, /*computeInvoke*/
                    true);
                    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
            return optimisticPutFuture(cacheCtx, loadFut, ret, keepBinary);
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture(e);
    } catch (RuntimeException e) {
        onException();
        throw e;
    }
}
Also used : GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) 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) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)27 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)12 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)11 CachePartialUpdateCheckedException (org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)11 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)7 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)7 Map (java.util.Map)6 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)4 GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)4 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)4