use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.
the class GridDhtAtomicCache method getAsync.
/**
* {@inheritDoc}
*/
@Override
protected IgniteInternalFuture<V> getAsync(final K key, final boolean forcePrimary, final boolean skipTx, final String taskName, final boolean deserializeBinary, final boolean skipVals, final boolean needVer) {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
CacheOperationContext opCtx = ctx.operationContextPerCall();
final ExpiryPolicy expiryPlc = skipVals ? null : opCtx != null ? opCtx.expiry() : null;
final boolean skipStore = opCtx != null && opCtx.skipStore();
final boolean recovery = opCtx != null && opCtx.recovery();
final ReadRepairStrategy readRepairStrategy = opCtx != null ? opCtx.readRepairStrategy() : null;
return asyncOp(new CO<IgniteInternalFuture<V>>() {
@Override
public IgniteInternalFuture<V> apply() {
return getAsync0(ctx.toCacheKeyObject(key), forcePrimary, taskName, deserializeBinary, recovery, readRepairStrategy, expiryPlc, skipVals, skipStore, needVer);
}
});
}
use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.
the class GridDhtAtomicCache method createSingleUpdateFuture.
/**
* Craete future for single key-val pair update.
*
* @param key Key.
* @param val Value.
* @param proc Processor.
* @param invokeArgs Invoke arguments.
* @param retval Return value flag.
* @param filter Filter.
* @return Future.
*/
private GridNearAtomicAbstractUpdateFuture createSingleUpdateFuture(K key, @Nullable V val, @Nullable EntryProcessor proc, @Nullable Object[] invokeArgs, boolean retval, @Nullable CacheEntryPredicate filter) {
CacheOperationContext opCtx = ctx.operationContextPerCall();
GridCacheOperation op;
Object val0;
if (val != null) {
op = UPDATE;
val0 = val;
} else if (proc != null) {
op = TRANSFORM;
val0 = proc;
} else {
op = DELETE;
val0 = null;
}
GridCacheDrInfo conflictPutVal = null;
GridCacheVersion conflictRmvVer = null;
if (opCtx != null && opCtx.hasDataCenterId()) {
Byte dcId = opCtx.dataCenterId();
assert dcId != null;
if (op == UPDATE) {
conflictPutVal = new GridCacheDrInfo(ctx.toCacheObject(val), nextVersion(dcId));
val0 = null;
} else if (op == GridCacheOperation.TRANSFORM) {
conflictPutVal = new GridCacheDrInfo(proc, nextVersion(dcId));
val0 = null;
} else
conflictRmvVer = nextVersion(dcId);
}
CacheEntryPredicate[] filters = CU.filterArray(filter);
if (conflictPutVal == null && conflictRmvVer == null) {
return new GridNearAtomicSingleUpdateFuture(ctx, this, ctx.config().getWriteSynchronizationMode(), op, key, val0, invokeArgs, retval, false, opCtx != null ? opCtx.expiry() : null, filters, ctx.kernalContext().job().currentTaskNameHash(), opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary(), opCtx != null && opCtx.recovery(), opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES);
} else {
return new GridNearAtomicUpdateFuture(ctx, this, ctx.config().getWriteSynchronizationMode(), op, Collections.singletonList(key), val0 != null ? Collections.singletonList(val0) : null, invokeArgs, conflictPutVal != null ? Collections.singleton(conflictPutVal) : null, conflictRmvVer != null ? Collections.singleton(conflictRmvVer) : null, retval, false, opCtx != null ? opCtx.expiry() : null, filters, ctx.kernalContext().job().currentTaskNameHash(), opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary(), opCtx != null && opCtx.recovery(), opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES);
}
}
use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.
the class GridDhtAtomicCache method invokeAll0.
/**
* @param async Async operation flag.
* @param keys Keys.
* @param entryProcessor Entry processor.
* @param args Entry processor arguments.
* @return Future.
*/
private <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAll0(boolean async, Set<? extends K> keys, final EntryProcessor<K, V, T> entryProcessor, Object... args) {
A.notNull(keys, "keys", entryProcessor, "entryProcessor");
final boolean statsEnabled = ctx.statisticsEnabled();
final long start = statsEnabled ? System.nanoTime() : 0L;
Map<? extends K, EntryProcessor> invokeMap = F.viewAsMap(keys, new C1<K, EntryProcessor>() {
@Override
public EntryProcessor apply(K k) {
return entryProcessor;
}
});
CacheOperationContext opCtx = ctx.operationContextPerCall();
final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> resFut = updateAll0(null, invokeMap, args, null, null, false, false, TRANSFORM, async);
return resFut.chain(new CX1<IgniteInternalFuture<Map<K, EntryProcessorResult<T>>>, Map<K, EntryProcessorResult<T>>>() {
@Override
public Map<K, EntryProcessorResult<T>> applyx(IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> fut) throws IgniteCheckedException {
Map<Object, EntryProcessorResult> resMap = (Map) fut.get();
if (statsEnabled)
metrics0().addInvokeTimeNanos(System.nanoTime() - start);
return ctx.unwrapInvokeResult(resMap, keepBinary);
}
});
}
use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.
the class GridDhtAtomicCache method getAllAsyncInternal.
/**
* @param keys Keys.
* @param forcePrimary Force primary flag.
* @param taskName Task name.
* @param deserializeBinary Deserialize binary flag.
* @param readRepairStrategy Read Repair strategy.
* @param skipVals Skip values flag.
* @param needVer Need version flag.
* @param asyncOp Async operation flag.
* @return Future.
*/
private IgniteInternalFuture<Map<K, V>> getAllAsyncInternal(@Nullable final Collection<? extends K> keys, final boolean forcePrimary, final String taskName, final boolean deserializeBinary, final boolean recovery, final ReadRepairStrategy readRepairStrategy, final boolean skipVals, final boolean needVer, boolean asyncOp) {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
if (F.isEmpty(keys))
return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
warnIfUnordered(keys, BulkOperation.GET);
CacheOperationContext opCtx = ctx.operationContextPerCall();
final ExpiryPolicy expiryPlc = skipVals ? null : opCtx != null ? opCtx.expiry() : null;
final boolean skipStore = opCtx != null && opCtx.skipStore();
if (asyncOp) {
return asyncOp(new CO<IgniteInternalFuture<Map<K, V>>>() {
@Override
public IgniteInternalFuture<Map<K, V>> apply() {
return getAllAsync0(ctx.cacheKeysView(keys), forcePrimary, taskName, deserializeBinary, recovery, readRepairStrategy, expiryPlc, skipVals, skipStore, needVer);
}
});
} else {
return getAllAsync0(ctx.cacheKeysView(keys), forcePrimary, taskName, deserializeBinary, recovery, readRepairStrategy, expiryPlc, skipVals, skipStore, needVer);
}
}
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;
}
Aggregations