use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.
the class GridLocalAtomicCache method updateAllInternal.
/**
* Entry point for all public update methods (put, remove, invoke).
*
* @param op Operation.
* @param keys Keys.
* @param vals Values.
* @param invokeArgs Optional arguments for EntryProcessor.
* @param expiryPlc Expiry policy.
* @param retval Return value required flag.
* @param rawRetval Return {@code GridCacheReturn} instance.
* @param filter Cache entry filter.
* @param writeThrough Write through.
* @param readThrough Read through.
* @return Update result.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
private Object updateAllInternal(GridCacheOperation op, Collection<? extends K> keys, @Nullable Iterable<?> vals, @Nullable Object[] invokeArgs, @Nullable ExpiryPolicy expiryPlc, boolean retval, boolean rawRetval, CacheEntryPredicate filter, boolean writeThrough, boolean readThrough, boolean keepBinary) throws IgniteCheckedException {
if (keyCheck)
validateCacheKeys(keys);
if (op == DELETE)
ctx.checkSecurity(SecurityPermission.CACHE_REMOVE);
else
ctx.checkSecurity(SecurityPermission.CACHE_PUT);
String taskName = ctx.kernalContext().job().currentTaskName();
GridCacheVersion ver = ctx.versions().next();
UUID subjId = ctx.subjectIdPerCall(null);
CacheEntryPredicate[] filters = CU.filterArray(filter);
ctx.shared().database().ensureFreeSpace(ctx.memoryPolicy());
if (writeThrough && keys.size() > 1) {
return updateWithBatch(op, keys, vals, invokeArgs, expiryPlc, ver, filters, keepBinary, subjId, taskName);
}
Iterator<?> valsIter = vals != null ? vals.iterator() : null;
IgniteBiTuple<Boolean, ?> res = null;
CachePartialUpdateCheckedException err = null;
boolean intercept = ctx.config().getInterceptor() != null;
for (K key : keys) {
if (key == null)
throw new NullPointerException("Null key.");
Object val = valsIter != null ? valsIter.next() : null;
if (val == null && op != DELETE)
throw new NullPointerException("Null value.");
KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
if (op == UPDATE)
val = ctx.toCacheObject(val);
else if (op == TRANSFORM)
ctx.kernalContext().resource().inject(val, GridResourceIoc.AnnotationSet.ENTRY_PROCESSOR, ctx.name());
while (true) {
GridCacheEntryEx entry = null;
try {
entry = entryEx(cacheKey);
GridTuple3<Boolean, Object, EntryProcessorResult<Object>> t = entry.innerUpdateLocal(ver, val == null ? DELETE : op, val, invokeArgs, writeThrough, readThrough, retval, keepBinary, expiryPlc, true, true, filters, intercept, subjId, taskName);
if (op == TRANSFORM) {
if (t.get3() != null) {
Map<K, EntryProcessorResult> computedMap;
if (res == null) {
computedMap = U.newHashMap(keys.size());
res = new IgniteBiTuple<>(true, computedMap);
} else
computedMap = (Map<K, EntryProcessorResult>) res.get2();
computedMap.put(key, t.get3());
}
} else if (res == null)
res = new T2(t.get1(), t.get2());
// While.
break;
} catch (GridCacheEntryRemovedException ignored) {
if (log.isDebugEnabled())
log.debug("Got removed entry while updating (will retry): " + key);
entry = null;
} catch (IgniteCheckedException e) {
if (err == null)
err = partialUpdateException();
err.add(F.asList(key), e);
U.error(log, "Failed to update key : " + key, e);
break;
} finally {
if (entry != null)
ctx.evicts().touch(entry, ctx.affinity().affinityTopologyVersion());
}
}
}
if (err != null)
throw err;
Object ret = res == null ? null : rawRetval ? new GridCacheReturn(ctx, true, keepBinary, res.get2(), res.get1()) : (retval || op == TRANSFORM) ? res.get2() : res.get1();
if (op == TRANSFORM && ret == null)
ret = Collections.emptyMap();
return ret;
}
use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.
the class GridNearTxLocal method lockAllAsync.
/**
* @param cacheCtx Cache context.
* @param keys Keys.
* @param retval Return value flag.
* @param read Read flag.
* @param createTtl Create ttl.
* @param accessTtl Access ttl.
* @param <K> Key type.
* @param skipStore Skip store flag.
* @param keepBinary Keep binary flag.
* @return Future with respond.
*/
public <K> IgniteInternalFuture<GridCacheReturn> lockAllAsync(GridCacheContext cacheCtx, final Collection<? extends K> keys, boolean retval, boolean read, long createTtl, long accessTtl, boolean skipStore, boolean keepBinary) {
assert pessimistic();
try {
checkValid();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
if (F.isEmpty(keys))
return new GridFinishedFuture<>(ret);
init();
if (log.isDebugEnabled())
log.debug("Before acquiring transaction lock on keys: " + keys);
long timeout = remainingTime();
if (timeout == -1)
return new GridFinishedFuture<>(timeoutException());
IgniteInternalFuture<Boolean> fut = cacheCtx.colocated().lockAllAsyncInternal(keys, timeout, this, isInvalidate(), read, retval, isolation, createTtl, accessTtl, CU.empty0(), skipStore, keepBinary);
return new GridEmbeddedFuture<>(fut, new PLC1<GridCacheReturn>(ret, false) {
@Override
protected GridCacheReturn postLock(GridCacheReturn ret) {
if (log.isDebugEnabled())
log.debug("Acquired transaction lock on keys: " + keys);
return ret;
}
});
}
Aggregations