Search in sources :

Example 11 with CachePartialUpdateCheckedException

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

the class GridNearAtomicUpdateFuture method onDhtResponse.

/** {@inheritDoc} */
@Override
public void onDhtResponse(UUID nodeId, GridDhtAtomicNearResponse res) {
    GridCacheReturn opRes0;
    CachePartialUpdateCheckedException err0;
    AffinityTopologyVersion remapTopVer0;
    synchronized (this) {
        if (!checkFutureId(res.futureId()))
            return;
        PrimaryRequestState reqState;
        if (singleReq != null) {
            assert singleReq.req.nodeId().equals(res.primaryId());
            if (opRes == null && res.hasResult())
                opRes = res.result();
            if (singleReq.onDhtResponse(nodeId, res)) {
                opRes0 = opRes;
                err0 = err;
                remapTopVer0 = onAllReceived();
            } else
                return;
        } else {
            reqState = mappings != null ? mappings.get(res.primaryId()) : null;
            if (reqState != null) {
                if (opRes == null && res.hasResult())
                    opRes = res.result();
                if (reqState.onDhtResponse(nodeId, res)) {
                    assert mappings.size() > resCnt : "[mappings=" + mappings.size() + ", cnt=" + resCnt + ']';
                    resCnt++;
                    if (mappings.size() == resCnt) {
                        opRes0 = opRes;
                        err0 = err;
                        remapTopVer0 = onAllReceived();
                    } else
                        return;
                } else
                    return;
            } 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 12 with CachePartialUpdateCheckedException

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

the class GridNearAtomicAbstractUpdateFuture method onPrimaryError.

/**
     * @param req Request.
     * @param res Response.
     */
final void onPrimaryError(GridNearAtomicAbstractUpdateRequest req, GridNearAtomicUpdateResponse res) {
    assert res.error() != null;
    if (err == null)
        err = new CachePartialUpdateCheckedException("Failed to update keys (retry update if possible).");
    Collection<KeyCacheObject> keys0 = res.failedKeys() != null ? res.failedKeys() : req.keys();
    Collection<Object> keys = new ArrayList<>(keys0.size());
    for (KeyCacheObject key : keys0) keys.add(cctx.cacheObjectContext().unwrapBinaryIfNeeded(key, keepBinary, false));
    err.add(keys, res.error(), req.topologyVersion());
}
Also used : ArrayList(java.util.ArrayList) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 13 with CachePartialUpdateCheckedException

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

the class GridNearAtomicSingleUpdateFuture method onAllReceived.

/**
     * @return Non-null topology version if update should be remapped.
     */
private AffinityTopologyVersion onAllReceived() {
    assert Thread.holdsLock(this);
    assert futureMapped() : this;
    AffinityTopologyVersion remapTopVer0 = null;
    if (remapTopVer == null) {
        if (err != null && X.hasCause(err, CachePartialUpdateCheckedException.class) && X.hasCause(err, ClusterTopologyCheckedException.class) && storeFuture() && --remapCnt > 0) {
            ClusterTopologyCheckedException topErr = X.cause(err, ClusterTopologyCheckedException.class);
            if (!(topErr instanceof ClusterTopologyServerNotFoundException)) {
                CachePartialUpdateCheckedException cause = X.cause(err, CachePartialUpdateCheckedException.class);
                assert cause != null && cause.topologyVersion() != null : err;
                remapTopVer0 = new AffinityTopologyVersion(cause.topologyVersion().topologyVersion() + 1);
                err = null;
            }
        }
    } else
        remapTopVer0 = remapTopVer;
    if (remapTopVer0 != null) {
        cctx.mvcc().removeAtomicFuture(futId);
        reqState = null;
        topVer = AffinityTopologyVersion.ZERO;
        futId = 0;
        remapTopVer = null;
    }
    return remapTopVer0;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 14 with CachePartialUpdateCheckedException

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

the class GridNearAtomicSingleUpdateFuture method onNodeLeft.

/** {@inheritDoc} */
@Override
public boolean onNodeLeft(UUID nodeId) {
    GridCacheReturn opRes0 = null;
    CachePartialUpdateCheckedException err0 = null;
    AffinityTopologyVersion remapTopVer0 = null;
    GridNearAtomicCheckUpdateRequest checkReq = null;
    boolean rcvAll = false;
    long futId;
    synchronized (this) {
        if (!futureMapped())
            return false;
        futId = this.futId;
        if (reqState.req.nodeId.equals(nodeId)) {
            GridNearAtomicAbstractUpdateRequest req = reqState.onPrimaryFail();
            if (req != null) {
                GridNearAtomicUpdateResponse res = primaryFailedResponse(req);
                rcvAll = true;
                reqState.onPrimaryResponse(res, cctx);
                onPrimaryError(req, res);
            }
        } else {
            DhtLeftResult res = reqState.onDhtNodeLeft(nodeId);
            if (res == DhtLeftResult.DONE)
                rcvAll = true;
            else if (res == DhtLeftResult.ALL_RCVD_CHECK_PRIMARY)
                checkReq = new GridNearAtomicCheckUpdateRequest(reqState.req);
            else
                return false;
        }
        if (rcvAll) {
            opRes0 = opRes;
            err0 = err;
            remapTopVer0 = onAllReceived();
        }
    }
    if (checkReq != null)
        sendCheckUpdateRequest(checkReq);
    else if (rcvAll)
        finishUpdateFuture(opRes0, err0, remapTopVer0, futId);
    return false;
}
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 15 with CachePartialUpdateCheckedException

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

the class GridLocalAtomicCache method updateWithBatch.

/**
     * Updates entries using batched write-through.
     *
     * @param op Operation.
     * @param keys Keys.
     * @param vals Values.
     * @param invokeArgs Optional arguments for EntryProcessor.
     * @param expiryPlc Expiry policy.
     * @param ver Cache version.
     * @param filter Optional filter.
     * @param subjId Subject ID.
     * @param taskName Task name.
     * @return Results map for invoke operation.
     * @throws CachePartialUpdateCheckedException If update failed.
     */
@SuppressWarnings({ "ForLoopReplaceableByForEach", "unchecked" })
private Map<K, EntryProcessorResult> updateWithBatch(GridCacheOperation op, Collection<? extends K> keys, @Nullable Iterable<?> vals, @Nullable Object[] invokeArgs, @Nullable ExpiryPolicy expiryPlc, GridCacheVersion ver, @Nullable CacheEntryPredicate[] filter, boolean keepBinary, UUID subjId, String taskName) throws IgniteCheckedException {
    List<GridCacheEntryEx> locked = lockEntries(keys);
    try {
        int size = locked.size();
        Map<KeyCacheObject, CacheObject> putMap = null;
        Collection<KeyCacheObject> rmvKeys = null;
        List<CacheObject> writeVals = null;
        Map<K, EntryProcessorResult> invokeResMap = op == TRANSFORM ? U.<K, EntryProcessorResult>newHashMap(size) : null;
        List<GridCacheEntryEx> filtered = new ArrayList<>(size);
        CachePartialUpdateCheckedException err = null;
        Iterator<?> valsIter = vals != null ? vals.iterator() : null;
        boolean intercept = ctx.config().getInterceptor() != null;
        for (int i = 0; i < size; i++) {
            GridCacheEntryEx entry = locked.get(i);
            Object val = valsIter != null ? valsIter.next() : null;
            if (val == null && op != DELETE)
                throw new NullPointerException("Null value.");
            try {
                try {
                    if (!ctx.isAllLocked(entry, filter)) {
                        if (log.isDebugEnabled())
                            log.debug("Entry did not pass the filter (will skip write) [entry=" + entry + ", filter=" + Arrays.toString(filter) + ']');
                        continue;
                    }
                } catch (IgniteCheckedException e) {
                    if (err == null)
                        err = partialUpdateException();
                    err.add(F.asList(entry.key()), e);
                    continue;
                }
                if (op == TRANSFORM) {
                    ctx.kernalContext().resource().inject(val, GridResourceIoc.AnnotationSet.ENTRY_PROCESSOR, ctx.name());
                    EntryProcessor<Object, Object, Object> entryProcessor = (EntryProcessor<Object, Object, Object>) val;
                    CacheObject old = entry.innerGet(null, null, /*read-through*/
                    true, /*update-metrics*/
                    true, /*event*/
                    true, subjId, entryProcessor, taskName, null, keepBinary);
                    Object oldVal = null;
                    CacheInvokeEntry<Object, Object> invokeEntry = new CacheInvokeEntry<>(entry.key(), old, entry.version(), keepBinary, entry);
                    CacheObject updated;
                    Object updatedVal = null;
                    CacheInvokeResult invokeRes = null;
                    try {
                        Object computed = entryProcessor.process(invokeEntry, invokeArgs);
                        updatedVal = ctx.unwrapTemporary(invokeEntry.getValue());
                        updated = ctx.toCacheObject(updatedVal);
                        if (computed != null)
                            invokeRes = CacheInvokeResult.fromResult(ctx.unwrapTemporary(computed));
                    } catch (Exception e) {
                        invokeRes = CacheInvokeResult.fromError(e);
                        updated = old;
                    }
                    if (invokeRes != null)
                        invokeResMap.put((K) entry.key().value(ctx.cacheObjectContext(), false), invokeRes);
                    if (updated == null) {
                        if (intercept) {
                            IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor().onBeforeRemove(new CacheLazyEntry(ctx, entry.key(), invokeEntry.key(), old, oldVal, keepBinary));
                            if (ctx.cancelRemove(interceptorRes))
                                continue;
                        }
                        // Update previous batch.
                        if (putMap != null) {
                            err = updatePartialBatch(filtered, ver, writeVals, putMap, null, expiryPlc, keepBinary, err, subjId, taskName);
                            putMap = null;
                            writeVals = null;
                            filtered = new ArrayList<>();
                        }
                        // Start collecting new batch.
                        if (rmvKeys == null)
                            rmvKeys = new ArrayList<>(size);
                        rmvKeys.add(entry.key());
                    } else {
                        if (intercept) {
                            Object interceptorVal = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(ctx, entry.key(), invokeEntry.getKey(), old, oldVal, keepBinary), updatedVal);
                            if (interceptorVal == null)
                                continue;
                            updated = ctx.toCacheObject(ctx.unwrapTemporary(interceptorVal));
                        }
                        // Update previous batch.
                        if (rmvKeys != null) {
                            err = updatePartialBatch(filtered, ver, null, null, rmvKeys, expiryPlc, keepBinary, err, subjId, taskName);
                            rmvKeys = null;
                            filtered = new ArrayList<>();
                        }
                        if (putMap == null) {
                            putMap = new LinkedHashMap<>(size, 1.0f);
                            writeVals = new ArrayList<>(size);
                        }
                        putMap.put(entry.key(), updated);
                        writeVals.add(updated);
                    }
                } else if (op == UPDATE) {
                    CacheObject cacheVal = ctx.toCacheObject(val);
                    if (intercept) {
                        CacheObject old = entry.innerGet(null, null, /*read-through*/
                        ctx.loadPreviousValue(), /**update-metrics*/
                        true, /**event*/
                        true, subjId, null, taskName, null, keepBinary);
                        Object interceptorVal = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(ctx, entry.key(), old, keepBinary), val);
                        if (interceptorVal == null)
                            continue;
                        cacheVal = ctx.toCacheObject(ctx.unwrapTemporary(interceptorVal));
                    }
                    if (putMap == null) {
                        putMap = new LinkedHashMap<>(size, 1.0f);
                        writeVals = new ArrayList<>(size);
                    }
                    putMap.put(entry.key(), cacheVal);
                    writeVals.add(cacheVal);
                } else {
                    assert op == DELETE;
                    if (intercept) {
                        CacheObject old = entry.innerGet(null, null, /*read-through*/
                        ctx.loadPreviousValue(), /**update-metrics*/
                        true, /**event*/
                        true, subjId, null, taskName, null, keepBinary);
                        IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor().onBeforeRemove(new CacheLazyEntry(ctx, entry.key(), old, keepBinary));
                        if (ctx.cancelRemove(interceptorRes))
                            continue;
                    }
                    if (rmvKeys == null)
                        rmvKeys = new ArrayList<>(size);
                    rmvKeys.add(entry.key());
                }
                filtered.add(entry);
            } catch (IgniteCheckedException e) {
                if (err == null)
                    err = partialUpdateException();
                err.add(F.asList(entry.key()), e);
            } catch (GridCacheEntryRemovedException ignore) {
                assert false : "Entry cannot become obsolete while holding lock.";
            }
        }
        // Store final batch.
        if (putMap != null || rmvKeys != null) {
            err = updatePartialBatch(filtered, ver, writeVals, putMap, rmvKeys, expiryPlc, keepBinary, err, subjId, taskName);
        } else
            assert filtered.isEmpty();
        if (err != null)
            throw err;
        return invokeResMap;
    } finally {
        unlockEntries(locked);
    }
}
Also used : CacheLazyEntry(org.apache.ignite.internal.processors.cache.CacheLazyEntry) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ArrayList(java.util.ArrayList) CacheInvokeResult(org.apache.ignite.internal.processors.cache.CacheInvokeResult) LinkedHashMap(java.util.LinkedHashMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) EntryProcessor(javax.cache.processor.EntryProcessor) CacheInvokeEntry(org.apache.ignite.internal.processors.cache.CacheInvokeEntry) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

CachePartialUpdateCheckedException (org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)17 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)9 Map (java.util.Map)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)4 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 UUID (java.util.UUID)2 EntryProcessorException (javax.cache.processor.EntryProcessorException)2 EntryProcessorResult (javax.cache.processor.EntryProcessorResult)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)2 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)2 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1