Search in sources :

Example 51 with CacheOperationContext

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

the class GridDhtColocatedLockFuture method mapAsPrimary.

/**
 * Tries to map this future in assumption that local node is primary for all keys passed in.
 * If node is not primary for one of the keys, then mapping is reverted and full remote mapping is performed.
 *
 * @param keys Keys to lock.
 * @param topVer Topology version.
 * @return {@code True} if all keys were mapped locally, {@code false} if full mapping should be performed.
 * @throws IgniteCheckedException If key cannot be added to mapping.
 */
private boolean mapAsPrimary(Collection<KeyCacheObject> keys, AffinityTopologyVersion topVer) throws IgniteCheckedException {
    // Assign keys to primary nodes.
    Collection<KeyCacheObject> distributedKeys = new ArrayList<>(keys.size());
    boolean explicit = false;
    for (KeyCacheObject key : keys) {
        if (!cctx.affinity().primaryByKey(cctx.localNode(), key, topVer)) {
            // Remove explicit locks added so far.
            for (KeyCacheObject k : keys) cctx.mvcc().removeExplicitLock(threadId, cctx.txKey(k), lockVer);
            return false;
        }
        explicit |= addLocalKey(key, topVer, distributedKeys);
        if (isDone())
            return true;
    }
    if (tx != null) {
        if (explicit)
            tx.markExplicit(cctx.localNodeId());
        tx.colocatedLocallyMapped(true);
    }
    if (!distributedKeys.isEmpty()) {
        if (tx != null) {
            for (KeyCacheObject key : distributedKeys) tx.addKeyMapping(cctx.txKey(key), cctx.localNode());
        }
        lockLocally(distributedKeys, topVer);
    }
    GridDhtPartitionsExchangeFuture lastFinishedFut = cctx.shared().exchange().lastFinishedFuture();
    CacheOperationContext opCtx = cctx.operationContextPerCall();
    CacheInvalidStateException validateCacheE = lastFinishedFut.validateCache(cctx, opCtx != null && opCtx.recovery(), read, null, keys);
    if (validateCacheE != null)
        onDone(validateCacheE);
    return true;
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) ArrayList(java.util.ArrayList) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 52 with CacheOperationContext

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

the class IgniteDrDataStreamerCacheUpdater method receive.

/**
 * {@inheritDoc}
 */
@Override
public void receive(IgniteCache<KeyCacheObject, CacheObject> cache0, Collection<Map.Entry<KeyCacheObject, CacheObject>> col) {
    try {
        String cacheName = cache0.getConfiguration(CacheConfiguration.class).getName();
        GridKernalContext ctx = ((IgniteKernal) cache0.unwrap(Ignite.class)).context();
        IgniteLogger log = ctx.log(IgniteDrDataStreamerCacheUpdater.class);
        GridCacheAdapter internalCache = ctx.cache().internalCache(cacheName);
        CacheOperationContext opCtx = ((IgniteCacheProxy) cache0).context().operationContextPerCall();
        IgniteInternalCache cache = opCtx != null ? new GridCacheProxyImpl(internalCache.context(), internalCache, opCtx) : internalCache;
        assert !F.isEmpty(col);
        if (log.isDebugEnabled())
            log.debug("Running DR put job [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
        CacheObjectContext cacheObjCtx = cache.context().cacheObjectContext();
        for (Map.Entry<KeyCacheObject, CacheObject> entry0 : col) {
            GridCacheRawVersionedEntry entry = (GridCacheRawVersionedEntry) entry0;
            entry.unmarshal(cacheObjCtx, ctx.config().getMarshaller());
            KeyCacheObject key = entry.getKey();
            // Ensure that receiver to not receive special-purpose values for TTL and expire time.
            assert entry.ttl() != CU.TTL_NOT_CHANGED && entry.ttl() != CU.TTL_ZERO && entry.ttl() >= 0;
            assert entry.expireTime() != CU.EXPIRE_TIME_CALCULATE && entry.expireTime() >= 0;
            CacheObject cacheVal = entry.getValue();
            GridCacheDrInfo val = cacheVal != null ? entry.ttl() != CU.TTL_ETERNAL ? new GridCacheDrExpirationInfo(cacheVal, entry.version(), entry.ttl(), entry.expireTime()) : new GridCacheDrInfo(cacheVal, entry.version()) : null;
            if (val == null)
                cache.removeAllConflict(Collections.singletonMap(key, entry.version()));
            else
                cache.putAllConflict(Collections.singletonMap(key, val));
        }
        if (log.isDebugEnabled())
            log.debug("DR put job finished [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridCacheProxyImpl(org.apache.ignite.internal.processors.cache.GridCacheProxyImpl) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheDrExpirationInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Ignite(org.apache.ignite.Ignite) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteLogger(org.apache.ignite.IgniteLogger) GridCacheRawVersionedEntry(org.apache.ignite.internal.processors.cache.version.GridCacheRawVersionedEntry) Map(java.util.Map) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 53 with CacheOperationContext

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

the class GridCacheQueueAdapter method withKeepBinary.

/**
 * {@inheritDoc}
 */
@Override
public <V1> IgniteQueue<V1> withKeepBinary() {
    CacheOperationContext opCtx = cctx.operationContextPerCall();
    if (opCtx != null && opCtx.isKeepBinary())
        return (GridCacheQueueAdapter<V1>) this;
    opCtx = opCtx == null ? new CacheOperationContext(false, true, null, false, null, false, null, DFLT_ALLOW_ATOMIC_OPS_IN_TX) : opCtx.keepBinary();
    cctx.operationContextPerCall(opCtx);
    return (GridCacheQueueAdapter<V1>) this;
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext)

Example 54 with CacheOperationContext

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

the class GridLocalAtomicCache method remove0.

/**
 * {@inheritDoc}
 */
@Override
public boolean remove0(K key, final CacheEntryPredicate filter) throws IgniteCheckedException {
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    Boolean rmv = (Boolean) updateAllInternal(DELETE, Collections.singleton(key), null, null, expiryPerCall(), false, false, filter, ctx.writeThrough(), ctx.readThrough(), opCtx != null && opCtx.isKeepBinary());
    assert rmv != null;
    return rmv;
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext)

Example 55 with CacheOperationContext

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

the class GridLocalAtomicCache method expiryPerCall.

/**
 * @return Expiry policy.
 */
@Nullable
private ExpiryPolicy expiryPerCall() {
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    ExpiryPolicy expiry = opCtx != null ? opCtx.expiry() : null;
    if (expiry == null)
        expiry = ctx.expiry();
    return expiry;
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)86 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)33 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)29 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)29 Map (java.util.Map)27 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)23 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)21 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)20 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)18 LinkedHashMap (java.util.LinkedHashMap)17 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)17 HashMap (java.util.HashMap)13 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)13 GridCacheConcurrentMap (org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)12 ArrayList (java.util.ArrayList)11 CacheException (javax.cache.CacheException)11 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)11 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)11 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)11