Search in sources :

Example 11 with GridCacheContext

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

the class GridDhtTxPrepareFuture method addDhtValues.

/**
     * @param res Response being sent.
     */
private void addDhtValues(GridNearTxPrepareResponse res) {
    // Interceptor on near node needs old values to execute callbacks.
    if (!F.isEmpty(writes)) {
        for (IgniteTxEntry e : writes) {
            IgniteTxEntry txEntry = tx.entry(e.txKey());
            assert txEntry != null : "Missing tx entry for key [tx=" + tx + ", key=" + e.txKey() + ']';
            GridCacheContext cacheCtx = txEntry.context();
            while (true) {
                try {
                    GridCacheEntryEx entry = txEntry.cached();
                    GridCacheVersion dhtVer = entry.version();
                    CacheObject val0 = entry.valueBytes();
                    if (val0 != null)
                        res.addOwnedValue(txEntry.txKey(), dhtVer, val0);
                    break;
                } catch (GridCacheEntryRemovedException ignored) {
                    // Retry.
                    txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
                }
            }
        }
    }
    for (Map.Entry<IgniteTxKey, GridCacheVersion> ver : dhtVerMap.entrySet()) {
        IgniteTxEntry txEntry = tx.entry(ver.getKey());
        if (res.hasOwnedValue(ver.getKey()))
            continue;
        assert txEntry != null : ver;
        GridCacheContext cacheCtx = txEntry.context();
        while (true) {
            try {
                GridCacheEntryEx entry = txEntry.cached();
                GridCacheVersion dhtVer = entry.version();
                if (ver.getValue() == null || !ver.getValue().equals(dhtVer)) {
                    CacheObject val0 = entry.valueBytes();
                    res.addOwnedValue(txEntry.txKey(), dhtVer, val0);
                }
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                // Retry.
                txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
            }
        }
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with GridCacheContext

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

the class GridDhtTxPrepareFuture method versionCheckError.

/**
     * @param entry Entry.
     * @return Optimistic version check error.
     */
private IgniteTxOptimisticCheckedException versionCheckError(IgniteTxEntry entry) {
    StringBuilder msg = new StringBuilder("Failed to prepare transaction, read/write conflict [");
    GridCacheContext cctx = entry.context();
    try {
        Object key = cctx.unwrapBinaryIfNeeded(entry.key(), entry.keepBinary(), false);
        assert key != null : entry.key();
        if (S.INCLUDE_SENSITIVE)
            msg.append("key=").append(key.toString()).append(", keyCls=").append(key.getClass().getName());
    } catch (Exception e) {
        msg.append("key=<failed to get key: ").append(e.toString()).append(">");
    }
    try {
        GridCacheEntryEx entryEx = entry.cached();
        CacheObject cacheVal = entryEx != null ? entryEx.rawGet() : null;
        Object val = cacheVal != null ? cctx.unwrapBinaryIfNeeded(cacheVal, entry.keepBinary(), false) : null;
        if (val != null) {
            if (S.INCLUDE_SENSITIVE)
                msg.append(", val=").append(val.toString()).append(", valCls=").append(val.getClass().getName());
        } else
            msg.append(", val=null");
    } catch (Exception e) {
        msg.append(", val=<failed to get value: ").append(e.toString()).append(">");
    }
    msg.append(", cache=").append(cctx.name()).append(", thread=").append(Thread.currentThread()).append("]");
    return new IgniteTxOptimisticCheckedException(msg.toString());
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)

Example 13 with GridCacheContext

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

the class GridDhtAtomicSingleUpdateRequest method finishUnmarshal.

/** {@inheritDoc} */
@Override
public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
    super.finishUnmarshal(ctx, ldr);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    finishUnmarshalObject(key, cctx, ldr);
    finishUnmarshalObject(val, cctx, ldr);
    finishUnmarshalObject(prevVal, cctx, ldr);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext)

Example 14 with GridCacheContext

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

the class GridNearAtomicFullUpdateRequest method prepareMarshal.

/** {@inheritDoc} */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    if (expiryPlc != null && expiryPlcBytes == null)
        expiryPlcBytes = CU.marshal(cctx, new IgniteExternalizableExpiryPolicy(expiryPlc));
    prepareMarshalCacheObjects(keys, cctx);
    if (filter != null) {
        boolean hasFilter = false;
        for (CacheEntryPredicate p : filter) {
            if (p != null) {
                hasFilter = true;
                p.prepareMarshal(cctx);
            }
        }
        if (!hasFilter)
            filter = null;
    }
    if (op == TRANSFORM) {
        // force addition of deployment info for entry processors if P2P is enabled globally.
        if (!addDepInfo && ctx.deploymentEnabled())
            addDepInfo = true;
        if (entryProcessorsBytes == null)
            entryProcessorsBytes = marshalCollection(entryProcessors, cctx);
        if (invokeArgsBytes == null)
            invokeArgsBytes = marshalInvokeArguments(invokeArgs, cctx);
    } else
        prepareMarshalCacheObjects(vals, cctx);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate)

Example 15 with GridCacheContext

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

the class GridNearAtomicFullUpdateRequest method finishUnmarshal.

/** {@inheritDoc} */
@Override
public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
    super.finishUnmarshal(ctx, ldr);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    if (expiryPlcBytes != null && expiryPlc == null)
        expiryPlc = U.unmarshal(ctx, expiryPlcBytes, U.resolveClassLoader(ldr, ctx.gridConfig()));
    finishUnmarshalCacheObjects(keys, cctx, ldr);
    if (filter != null) {
        for (CacheEntryPredicate p : filter) {
            if (p != null)
                p.finishUnmarshal(cctx, ldr);
        }
    }
    if (op == TRANSFORM) {
        if (entryProcessors == null)
            entryProcessors = unmarshalCollection(entryProcessorsBytes, ctx, ldr);
        if (invokeArgs == null)
            invokeArgs = unmarshalInvokeArguments(invokeArgsBytes, ctx, ldr);
    } else
        finishUnmarshalCacheObjects(vals, cctx, ldr);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate)

Aggregations

GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)121 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)20 ClusterNode (org.apache.ignite.cluster.ClusterNode)18 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)15 UUID (java.util.UUID)14 HashMap (java.util.HashMap)13 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)13 Map (java.util.Map)12 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)12 ArrayList (java.util.ArrayList)11 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)11 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)10 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)10 List (java.util.List)9 IgniteException (org.apache.ignite.IgniteException)8 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)8 Ignite (org.apache.ignite.Ignite)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7