Search in sources :

Example 21 with CacheOperationContext

use of org.apache.ignite.internal.processors.cache.CacheOperationContext 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;
    if (cacheCtx.mvccEnabled())
        return mvccPutAllAsync0(cacheCtx, Collections.singletonMap(key, val), entryProcessor == null ? null : Collections.singletonMap(key, entryProcessor), invokeArgs, retval, filter);
    try {
        beforePut(cacheCtx, retval, false);
        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);
        try {
            loadFut.get();
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture(e);
        }
        long timeout = remainingTime();
        if (timeout == -1)
            return new GridFinishedFuture<>(timeoutException());
        if (isRollbackOnly())
            return new GridFinishedFuture<>(rollbackException());
        if (pessimistic()) {
            final Collection<KeyCacheObject> enlisted = Collections.singleton(cacheKey);
            if (log.isDebugEnabled())
                log.debug("Before acquiring transaction lock for put on key: " + enlisted);
            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) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) 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) 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)

Example 22 with CacheOperationContext

use of org.apache.ignite.internal.processors.cache.CacheOperationContext 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) {
    if (cacheCtx.mvccEnabled())
        return mvccPutAllAsync0(cacheCtx, map, invokeMap, invokeArgs, retval, null);
    try {
        beforePut(cacheCtx, retval, false);
    } 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);
        try {
            loadFut.get();
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture(e);
        }
        long timeout = remainingTime();
        if (timeout == -1)
            return new GridFinishedFuture<>(timeoutException());
        if (isRollbackOnly())
            return new GridFinishedFuture<>(rollbackException());
        if (pessimistic()) {
            if (log.isDebugEnabled())
                log.debug("Before acquiring transaction lock for put on keys: " + enlisted);
            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) MARKED_ROLLBACK(org.apache.ignite.transactions.TransactionState.MARKED_ROLLBACK) 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) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) 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) 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) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap)

Example 23 with CacheOperationContext

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

the class GridNearTxLocal method updateAsync.

/**
 * Executes key-value update operation in Mvcc mode.
 *
 * @param cacheCtx Cache context.
 * @param it Entries iterator.
 * @param retval Return value flag.
 * @param filter Filter.
 * @param timeout Timeout.
 * @param sequential Sequential locking flag.
 * @return Operation future.
 */
private IgniteInternalFuture<GridCacheReturn> updateAsync(GridCacheContext cacheCtx, UpdateSourceIterator<?> it, boolean retval, @Nullable CacheEntryPredicate filter, long timeout, boolean sequential) {
    try {
        final CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
        final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
        /* TODO: IGNITE-9688: 'sequential' is always true here which can slowdown bulk operations,
             but possibly we can safely optimize this. */
        GridNearTxEnlistFuture fut = new GridNearTxEnlistFuture(cacheCtx, this, timeout, it, 0, sequential, filter, retval, keepBinary);
        fut.init();
        return nonInterruptable(new GridEmbeddedFuture<>(fut.chain(new CX1<IgniteInternalFuture<GridCacheReturn>, Boolean>() {

            @Override
            public Boolean applyx(IgniteInternalFuture<GridCacheReturn> fut0) throws IgniteCheckedException {
                fut0.get();
                return true;
            }
        }), new PLC1<GridCacheReturn>(null) {

            @Override
            protected GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
                GridCacheReturn futRes = fut.get();
                assert futRes != null;
                mvccSnapshot.incrementOperationCounter();
                Object val = futRes.value();
                if (futRes.invokeResult() && val != null) {
                    assert val instanceof Map;
                    val = cacheCtx.unwrapInvokeResult((Map) val, keepBinary);
                }
                return new GridCacheReturn(cacheCtx, true, keepBinary, U.deploymentClassLoader(cctx.kernalContext(), deploymentLdrId), val, futRes.success());
            }
        }));
    } catch (RuntimeException e) {
        onException();
        throw e;
    }
}
Also used : GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) 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) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap)

Example 24 with CacheOperationContext

use of org.apache.ignite.internal.processors.cache.CacheOperationContext 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) {
    if (cacheCtx.mvccEnabled())
        return mvccRemoveAllAsync0(cacheCtx, keys, retval, filter);
    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);
    try {
        loadFut.get();
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture(e);
    }
    long timeout = remainingTime();
    if (timeout == -1)
        return new GridFinishedFuture<>(timeoutException());
    if (isRollbackOnly())
        return new GridFinishedFuture<>(rollbackException());
    if (log.isDebugEnabled())
        log.debug("Remove keys: " + enlisted);
    // to be rolled back.
    if (pessimistic()) {
        if (log.isDebugEnabled())
            log.debug("Before acquiring transaction lock for remove on keys: " + enlisted);
        IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, false, retval, isolation, isInvalidate(), -1L, -1L);
        PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {

            /**
             * {@inheritDoc}
             */
            @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, U.deploymentClassLoader(cctx.kernalContext(), deploymentLdrId), 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) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) 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) 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 25 with CacheOperationContext

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

the class IgniteH2Indexing method executeUpdate.

/**
 * Execute DML statement, possibly with few re-attempts in case of concurrent data modifications.
 *
 * @param qryId Query id.
 * @param qryDesc Query descriptor.
 * @param qryParams Query parameters.
 * @param dml DML command.
 * @param loc Query locality flag.
 * @param filters Cache name and key filter.
 * @param cancel Cancel.
 * @return Update result (modified items count and failed keys).
 * @throws IgniteCheckedException if failed.
 */
@SuppressWarnings("IfMayBeConditional")
private UpdateResult executeUpdate(long qryId, QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultDml dml, boolean loc, IndexingQueryFilter filters, GridQueryCancel cancel) throws IgniteCheckedException {
    Object[] errKeys = null;
    long items = 0;
    PartitionResult partRes = null;
    GridCacheContext<?, ?> cctx = dml.plan().cacheContext();
    boolean transactional = cctx != null && cctx.mvccEnabled();
    int maxRetryCnt = transactional ? 1 : DFLT_UPDATE_RERUN_ATTEMPTS;
    for (int i = 0; i < maxRetryCnt; i++) {
        CacheOperationContext opCtx = cctx != null ? DmlUtils.setKeepBinaryContext(cctx) : null;
        UpdateResult r;
        try {
            if (transactional)
                r = executeUpdateTransactional(qryId, qryDesc, qryParams, dml, loc, cancel);
            else
                r = executeUpdateNonTransactional(qryId, qryDesc, qryParams, dml, loc, filters, cancel);
        } finally {
            if (opCtx != null)
                DmlUtils.restoreKeepBinaryContext(cctx, opCtx);
        }
        items += r.counter();
        errKeys = r.errorKeys();
        partRes = r.partitionResult();
        if (F.isEmpty(errKeys))
            break;
    }
    if (F.isEmpty(errKeys) && partRes == null) {
        if (items == 1L)
            return UpdateResult.ONE;
        else if (items == 0L)
            return UpdateResult.ZERO;
    }
    return new UpdateResult(items, errKeys, partRes);
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) PartitionResult(org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult)

Aggregations

CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)48 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)18 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)17 Map (java.util.Map)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)13 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)12 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)11 LinkedHashMap (java.util.LinkedHashMap)9 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)9 HashMap (java.util.HashMap)7 GridCacheConcurrentMap (org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)7 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)7 ArrayList (java.util.ArrayList)6 CacheException (javax.cache.CacheException)6 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)6 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)6 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)5 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)5