use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.
the class GridDhtAtomicCache method updateAll0.
/**
* Entry point for all public API put/transform methods.
*
* @param map Put map. Either {@code map}, {@code invokeMap} or {@code conflictPutMap} should be passed.
* @param invokeMap Invoke map. Either {@code map}, {@code invokeMap} or {@code conflictPutMap} should be passed.
* @param invokeArgs Optional arguments for EntryProcessor.
* @param conflictPutMap Conflict put map.
* @param conflictRmvMap Conflict remove map.
* @param retval Return value required flag.
* @param rawRetval Return {@code GridCacheReturn} instance.
* @param async Async operation flag.
* @return Completion future.
*/
@SuppressWarnings("ConstantConditions")
private IgniteInternalFuture updateAll0(@Nullable Map<? extends K, ? extends V> map, @Nullable Map<? extends K, ? extends EntryProcessor> invokeMap, @Nullable Object[] invokeArgs, @Nullable Map<KeyCacheObject, GridCacheDrInfo> conflictPutMap, @Nullable Map<KeyCacheObject, GridCacheVersion> conflictRmvMap, final boolean retval, final boolean rawRetval, final GridCacheOperation op, boolean async) {
assert ctx.updatesAllowed();
ctx.checkSecurity(SecurityPermission.CACHE_PUT);
final CacheOperationContext opCtx = ctx.operationContextPerCall();
if (opCtx != null && opCtx.hasDataCenterId()) {
assert conflictPutMap == null : conflictPutMap;
assert conflictRmvMap == null : conflictRmvMap;
if (op == GridCacheOperation.TRANSFORM) {
assert invokeMap != null : invokeMap;
conflictPutMap = F.viewReadOnly((Map) invokeMap, new IgniteClosure<EntryProcessor, GridCacheDrInfo>() {
@Override
public GridCacheDrInfo apply(EntryProcessor o) {
return new GridCacheDrInfo(o, nextVersion(opCtx.dataCenterId()));
}
});
invokeMap = null;
} else if (op == GridCacheOperation.DELETE) {
assert map != null : map;
conflictRmvMap = F.viewReadOnly((Map) map, new IgniteClosure<V, GridCacheVersion>() {
@Override
public GridCacheVersion apply(V o) {
return nextVersion(opCtx.dataCenterId());
}
});
map = null;
} else {
assert map != null : map;
conflictPutMap = F.viewReadOnly((Map) map, new IgniteClosure<V, GridCacheDrInfo>() {
@Override
public GridCacheDrInfo apply(V o) {
return new GridCacheDrInfo(ctx.toCacheObject(o), nextVersion(opCtx.dataCenterId()));
}
});
map = null;
}
}
int taskNameHash = ctx.kernalContext().job().currentTaskNameHash();
final GridNearAtomicUpdateFuture updateFut = new GridNearAtomicUpdateFuture(ctx, this, ctx.config().getWriteSynchronizationMode(), op, map != null ? map.keySet() : invokeMap != null ? invokeMap.keySet() : conflictPutMap != null ? conflictPutMap.keySet() : conflictRmvMap.keySet(), map != null ? map.values() : invokeMap != null ? invokeMap.values() : null, invokeArgs, (Collection) (conflictPutMap != null ? conflictPutMap.values() : null), conflictRmvMap != null ? conflictRmvMap.values() : null, retval, rawRetval, opCtx != null ? opCtx.expiry() : null, CU.filterArray(null), taskNameHash, opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary(), opCtx != null && opCtx.recovery(), opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES);
if (async) {
return asyncOp(new CO<IgniteInternalFuture<Object>>() {
@Override
public IgniteInternalFuture<Object> apply() {
updateFut.map();
return updateFut;
}
});
} else {
updateFut.map();
return updateFut;
}
}
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);
}
}
Aggregations