use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.
the class GridNearAtomicSingleUpdateFuture method checkDhtNodes.
/**
* @param futId Future ID.
*/
private void checkDhtNodes(long futId) {
GridCacheReturn opRes0 = null;
CachePartialUpdateCheckedException err0 = null;
AffinityTopologyVersion remapTopVer0 = null;
GridNearAtomicCheckUpdateRequest checkReq = null;
synchronized (this) {
if (!checkFutureId(futId))
return;
assert reqState != null;
DhtLeftResult res = reqState.checkDhtNodes(cctx);
if (res == DhtLeftResult.DONE) {
opRes0 = opRes;
err0 = err;
remapTopVer0 = onAllReceived();
} else if (res == DhtLeftResult.ALL_RCVD_CHECK_PRIMARY)
checkReq = new GridNearAtomicCheckUpdateRequest(reqState.req);
else
return;
}
if (checkReq != null)
sendCheckUpdateRequest(checkReq);
else
finishUpdateFuture(opRes0, err0, remapTopVer0, futId);
}
use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.
the class GridNearAtomicSingleUpdateFuture method onDhtResponse.
/** {@inheritDoc} */
@Override
public void onDhtResponse(UUID nodeId, GridDhtAtomicNearResponse res) {
GridCacheReturn opRes0;
CachePartialUpdateCheckedException err0;
AffinityTopologyVersion remapTopVer0;
synchronized (this) {
if (!checkFutureId(res.futureId()))
return;
assert reqState != null;
assert reqState.req.nodeId().equals(res.primaryId());
if (opRes == null && res.hasResult())
opRes = res.result();
if (reqState.onDhtResponse(nodeId, res)) {
opRes0 = opRes;
err0 = err;
remapTopVer0 = onAllReceived();
} else
return;
}
UpdateErrors errors = res.errors();
if (errors != null) {
assert errors.error() != null;
completeFuture(null, errors.error(), res.futureId());
return;
}
finishUpdateFuture(opRes0, err0, remapTopVer0, res.futureId());
}
use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.
the class GridNearAtomicUpdateFuture method onPrimaryResponse.
/** {@inheritDoc} */
@SuppressWarnings({ "unchecked", "ThrowableResultOfMethodCallIgnored" })
@Override
public void onPrimaryResponse(UUID nodeId, GridNearAtomicUpdateResponse res, boolean nodeErr) {
GridNearAtomicAbstractUpdateRequest req;
AffinityTopologyVersion remapTopVer0 = null;
GridCacheReturn opRes0 = null;
CachePartialUpdateCheckedException err0 = null;
boolean rcvAll;
synchronized (this) {
if (!checkFutureId(res.futureId()))
return;
if (singleReq != null) {
req = singleReq.processPrimaryResponse(nodeId, res);
if (req == null)
return;
rcvAll = singleReq.onPrimaryResponse(res, cctx);
} else {
if (mappings == null)
return;
PrimaryRequestState reqState = mappings.get(nodeId);
if (reqState == null)
return;
req = reqState.processPrimaryResponse(nodeId, res);
if (req != null) {
if (reqState.onPrimaryResponse(res, cctx)) {
assert mappings.size() > resCnt : "[mappings=" + mappings.size() + ", cnt=" + resCnt + ']';
resCnt++;
rcvAll = mappings.size() == resCnt;
} else {
assert mappings.size() > resCnt : "[mappings=" + mappings.size() + ", cnt=" + resCnt + ']';
rcvAll = false;
}
} else
return;
}
assert req.topologyVersion().equals(topVer) : req;
if (res.remapTopologyVersion() != null) {
assert !req.topologyVersion().equals(res.remapTopologyVersion());
if (remapKeys == null)
remapKeys = U.newHashSet(req.size());
remapKeys.addAll(req.keys());
if (remapTopVer == null || remapTopVer.compareTo(res.remapTopologyVersion()) < 0)
remapTopVer = req.topologyVersion();
} else if (res.error() != null)
onPrimaryError(req, res);
else {
GridCacheReturn ret = res.returnValue();
if (op == TRANSFORM) {
if (ret != null) {
assert ret.value() == null || ret.value() instanceof Map : ret.value();
if (ret.value() != null) {
if (opRes != null)
opRes.mergeEntryProcessResults(ret);
else
opRes = ret;
}
}
} else
opRes = ret;
}
if (rcvAll) {
remapTopVer0 = onAllReceived();
if (remapTopVer0 == null) {
err0 = err;
opRes0 = opRes;
}
}
}
if (res.error() != null && res.failedKeys() == null) {
completeFuture(null, res.error(), res.futureId());
return;
}
if (rcvAll && nearEnabled) {
if (mappings != null) {
for (PrimaryRequestState reqState : mappings.values()) {
GridNearAtomicUpdateResponse res0 = reqState.req.response();
assert res0 != null : reqState;
updateNear(reqState.req, res0);
}
} else if (!nodeErr)
updateNear(req, res);
}
if (remapTopVer0 != null) {
waitAndRemap(remapTopVer0);
return;
}
if (rcvAll)
completeFuture(opRes0, err0, res.futureId());
}
use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.
the class GridNearTxLocal method putAllAsync0.
/**
* Internal method for all put and transform operations. Only one of {@code map}, {@code transformMap}
* maps must be non-null.
*
* @param cacheCtx Context.
* @param map Key-value map to store.
* @param invokeMap Invoke map.
* @param invokeArgs Optional arguments for EntryProcessor.
* @param drMap DR map.
* @param retval Key-transform value map to store.
* @return Operation future.
*/
@SuppressWarnings("unchecked")
private <K, V> IgniteInternalFuture putAllAsync0(final GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, @Nullable Map<? extends K, ? extends V> map, @Nullable Map<? extends K, ? extends EntryProcessor<K, V, Object>> invokeMap, @Nullable final Object[] invokeArgs, @Nullable Map<KeyCacheObject, GridCacheDrInfo> drMap, final boolean retval) {
try {
beforePut(cacheCtx, retval);
} catch (IgniteCheckedException e) {
return new GridFinishedFuture(e);
}
final CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
final Byte dataCenterId;
if (opCtx != null && opCtx.hasDataCenterId()) {
assert drMap == null : drMap;
assert map != null || invokeMap != null;
dataCenterId = opCtx.dataCenterId();
} else
dataCenterId = null;
// Cached entry may be passed only from entry wrapper.
final Map<?, ?> map0 = map;
final Map<?, EntryProcessor<K, V, Object>> invokeMap0 = (Map<K, EntryProcessor<K, V, Object>>) invokeMap;
if (log.isDebugEnabled())
log.debug("Called putAllAsync(...) [tx=" + this + ", map=" + map0 + ", retval=" + retval + "]");
assert map0 != null || invokeMap0 != null;
final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
if (F.isEmpty(map0) && F.isEmpty(invokeMap0)) {
if (implicit())
try {
commit();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
return new GridFinishedFuture<>(ret.success(true));
}
try {
Set<?> keySet = map0 != null ? map0.keySet() : invokeMap0.keySet();
final Collection<KeyCacheObject> enlisted = new ArrayList<>(keySet.size());
final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
final IgniteInternalFuture<Void> loadFut = enlistWrite(cacheCtx, entryTopVer, keySet, opCtx != null ? opCtx.expiry() : null, map0, invokeMap0, invokeArgs, retval, false, CU.filterArray(null), ret, enlisted, drMap, null, opCtx != null && opCtx.skipStore(), false, keepBinary, opCtx != null && opCtx.recovery(), dataCenterId);
if (pessimistic()) {
assert loadFut == null || loadFut.isDone() : loadFut;
if (loadFut != null) {
try {
loadFut.get();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture(e);
}
}
if (log.isDebugEnabled())
log.debug("Before acquiring transaction lock for put on keys: " + enlisted);
long timeout = remainingTime();
if (timeout == -1)
return new GridFinishedFuture<>(timeoutException());
IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, // Needed to force load from store.
invokeMap != null, /*read*/
retval, isolation, isInvalidate(), -1L, -1L);
PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {
@Override
public GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
if (log.isDebugEnabled())
log.debug("Acquired transaction lock for put on keys: " + enlisted);
postLockWrite(cacheCtx, enlisted, ret, /*remove*/
false, retval, /*read*/
false, -1L, CU.filterArray(null), /*computeInvoke*/
true);
return ret;
}
};
if (fut.isDone()) {
try {
return nonInterruptable(plc1.apply(fut.get(), null));
} catch (GridClosureException e) {
return new GridFinishedFuture<>(e.unwrap());
} catch (IgniteCheckedException e) {
try {
return nonInterruptable(plc1.apply(false, e));
} catch (Exception e1) {
return new GridFinishedFuture<>(e1);
}
}
} else {
return nonInterruptable(new GridEmbeddedFuture<>(fut, plc1));
}
} else
return optimisticPutFuture(cacheCtx, loadFut, ret, keepBinary);
} catch (RuntimeException e) {
onException();
throw e;
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheReturn in project ignite by apache.
the class GridNearTxLocal method putAsync0.
/**
* Internal method for single update operation.
*
* @param cacheCtx Cache context.
* @param key Key.
* @param val Value.
* @param entryProcessor Entry processor.
* @param invokeArgs Optional arguments for EntryProcessor.
* @param retval Return value flag.
* @param filter Filter.
* @return Operation future.
*/
private <K, V> IgniteInternalFuture putAsync0(final GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, K key, @Nullable V val, @Nullable EntryProcessor<K, V, Object> entryProcessor, @Nullable final Object[] invokeArgs, final boolean retval, @Nullable final CacheEntryPredicate filter) {
assert key != null;
try {
beforePut(cacheCtx, retval);
final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
final Byte dataCenterId = opCtx != null ? opCtx.dataCenterId() : null;
KeyCacheObject cacheKey = cacheCtx.toCacheKeyObject(key);
boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
final CacheEntryPredicate[] filters = CU.filterArray(filter);
final IgniteInternalFuture<Void> loadFut = enlistWrite(cacheCtx, entryTopVer, cacheKey, val, opCtx != null ? opCtx.expiry() : null, entryProcessor, invokeArgs, retval, /*lockOnly*/
false, filters, ret, opCtx != null && opCtx.skipStore(), /*singleRmv*/
false, keepBinary, opCtx != null && opCtx.recovery(), dataCenterId);
if (pessimistic()) {
assert loadFut == null || loadFut.isDone() : loadFut;
if (loadFut != null)
loadFut.get();
final Collection<KeyCacheObject> enlisted = Collections.singleton(cacheKey);
if (log.isDebugEnabled())
log.debug("Before acquiring transaction lock for put on key: " + enlisted);
long timeout = remainingTime();
if (timeout == -1)
return new GridFinishedFuture<>(timeoutException());
IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, // Needed to force load from store.
entryProcessor != null, /*read*/
retval, isolation, isInvalidate(), -1L, -1L);
PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {
@Override
public GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
if (log.isDebugEnabled())
log.debug("Acquired transaction lock for put on keys: " + enlisted);
postLockWrite(cacheCtx, enlisted, ret, /*remove*/
false, retval, /*read*/
false, -1L, filters, /*computeInvoke*/
true);
return ret;
}
};
if (fut.isDone()) {
try {
return nonInterruptable(plc1.apply(fut.get(), null));
} catch (GridClosureException e) {
return new GridFinishedFuture<>(e.unwrap());
} catch (IgniteCheckedException e) {
try {
return nonInterruptable(plc1.apply(false, e));
} catch (Exception e1) {
return new GridFinishedFuture<>(e1);
}
}
} else {
return nonInterruptable(new GridEmbeddedFuture<>(fut, plc1));
}
} else
return optimisticPutFuture(cacheCtx, loadFut, ret, keepBinary);
} catch (IgniteCheckedException e) {
return new GridFinishedFuture(e);
} catch (RuntimeException e) {
onException();
throw e;
}
}
Aggregations