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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations