use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class TcpCommunicationSpi method dumpStats.
/**
* Dumps SPI per-connection stats to logs.
*/
public void dumpStats() {
final IgniteLogger log = this.diagnosticLog;
if (log != null) {
StringBuilder sb = new StringBuilder();
dumpInfo(sb, null);
U.warn(log, sb.toString());
GridNioServer<Message> nioSrvr = this.nioSrvr;
if (nioSrvr != null) {
nioSrvr.dumpStats().listen(new CI1<IgniteInternalFuture<String>>() {
@Override
public void apply(IgniteInternalFuture<String> fut) {
try {
U.warn(log, fut.get());
} catch (Exception e) {
U.error(log, "Failed to dump NIO server statistics: " + e, e);
}
}
});
}
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridNearTxLocal method optimisticPutFuture.
/**
* @param cacheCtx Cache context.
* @param loadFut Missing keys load future.
* @param ret Future result.
* @param keepBinary Keep binary flag.
* @return Future.
*/
private IgniteInternalFuture optimisticPutFuture(final GridCacheContext cacheCtx, IgniteInternalFuture<Void> loadFut, final GridCacheReturn ret, final boolean keepBinary) {
if (implicit()) {
// with prepare response, if required.
assert loadFut.isDone();
try {
loadFut.get();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
return nonInterruptable(commitNearTxLocalAsync().chain(new CX1<IgniteInternalFuture<IgniteInternalTx>, GridCacheReturn>() {
@Override
public GridCacheReturn applyx(IgniteInternalFuture<IgniteInternalTx> txFut) throws IgniteCheckedException {
try {
txFut.get();
Object res = implicitRes.value();
if (implicitRes.invokeResult()) {
assert res == null || res instanceof Map : implicitRes;
res = cacheCtx.unwrapInvokeResult((Map) res, keepBinary);
}
return new GridCacheReturn(cacheCtx, true, keepBinary, res, implicitRes.success());
} catch (IgniteCheckedException | RuntimeException e) {
if (!(e instanceof NodeStoppingException))
rollbackNearTxLocalAsync();
throw e;
}
}
}));
} else {
return nonInterruptable(loadFut.chain(new CX1<IgniteInternalFuture<Void>, GridCacheReturn>() {
@Override
public GridCacheReturn applyx(IgniteInternalFuture<Void> f) throws IgniteCheckedException {
f.get();
return ret;
}
}));
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridNearTxLocal method loadMissing.
/**
* @param cacheCtx Cache context.
* @param readThrough Read through flag.
* @param async if {@code True}, then loading will happen in a separate thread.
* @param keys Keys.
* @param skipVals Skip values flag.
* @param needVer If {@code true} version is required for loaded values.
* @param c Closure to be applied for loaded values.
* @param expiryPlc Expiry policy.
* @return Future with {@code True} value if loading took place.
*/
public IgniteInternalFuture<Void> loadMissing(final GridCacheContext cacheCtx, AffinityTopologyVersion topVer, boolean readThrough, boolean async, final Collection<KeyCacheObject> keys, final boolean skipVals, final boolean needVer, boolean keepBinary, boolean recovery, final ExpiryPolicy expiryPlc, final GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c) {
IgniteCacheExpiryPolicy expiryPlc0 = optimistic() ? accessPolicy(cacheCtx, keys) : cacheCtx.cache().expiryPolicy(expiryPlc);
if (cacheCtx.isNear()) {
return cacheCtx.nearTx().txLoadAsync(this, topVer, keys, readThrough, /*deserializeBinary*/
false, recovery, expiryPlc0, skipVals, needVer).chain(new C1<IgniteInternalFuture<Map<Object, Object>>, Void>() {
@Override
public Void apply(IgniteInternalFuture<Map<Object, Object>> f) {
try {
Map<Object, Object> map = f.get();
processLoaded(map, keys, needVer, c);
return null;
} catch (Exception e) {
setRollbackOnly();
throw new GridClosureException(e);
}
}
});
} else if (cacheCtx.isColocated()) {
if (keys.size() == 1) {
final KeyCacheObject key = F.first(keys);
return cacheCtx.colocated().loadAsync(key, readThrough, /*force primary*/
needVer || !cacheCtx.config().isReadFromBackup(), topVer, CU.subjectId(this, cctx), resolveTaskName(), /*deserializeBinary*/
false, expiryPlc0, skipVals, needVer, /*keepCacheObject*/
true, recovery).chain(new C1<IgniteInternalFuture<Object>, Void>() {
@Override
public Void apply(IgniteInternalFuture<Object> f) {
try {
Object val = f.get();
processLoaded(key, val, needVer, skipVals, c);
return null;
} catch (Exception e) {
setRollbackOnly();
throw new GridClosureException(e);
}
}
});
} else {
return cacheCtx.colocated().loadAsync(keys, readThrough, /*force primary*/
needVer || !cacheCtx.config().isReadFromBackup(), topVer, CU.subjectId(this, cctx), resolveTaskName(), /*deserializeBinary*/
false, recovery, expiryPlc0, skipVals, needVer, /*keepCacheObject*/
true).chain(new C1<IgniteInternalFuture<Map<Object, Object>>, Void>() {
@Override
public Void apply(IgniteInternalFuture<Map<Object, Object>> f) {
try {
Map<Object, Object> map = f.get();
processLoaded(map, keys, needVer, c);
return null;
} catch (Exception e) {
setRollbackOnly();
throw new GridClosureException(e);
}
}
});
}
} else {
assert cacheCtx.isLocal();
return localCacheLoadMissing(cacheCtx, topVer, readThrough, async, keys, skipVals, needVer, keepBinary, recovery, expiryPlc, c);
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridNearTxLocal method removeAllAsync0.
/**
* @param cacheCtx Cache context.
* @param keys Keys to remove.
* @param drMap DR map.
* @param retval Flag indicating whether a value should be returned.
* @param filter Filter.
* @param singleRmv {@code True} for single key remove operation ({@link Cache#remove(Object)}.
* @return Future for asynchronous remove.
*/
@SuppressWarnings("unchecked")
private <K, V> IgniteInternalFuture<GridCacheReturn> removeAllAsync0(final GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, @Nullable final Collection<? extends K> keys, @Nullable Map<KeyCacheObject, GridCacheVersion> drMap, final boolean retval, @Nullable final CacheEntryPredicate filter, boolean singleRmv) {
try {
checkUpdatesAllowed(cacheCtx);
} catch (IgniteCheckedException e) {
return new GridFinishedFuture(e);
}
cacheCtx.checkSecurity(SecurityPermission.CACHE_REMOVE);
if (retval)
needReturnValue(true);
final Collection<?> keys0;
if (drMap != null) {
assert keys == null;
keys0 = drMap.keySet();
} else
keys0 = keys;
CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
final Byte dataCenterId;
if (opCtx != null && opCtx.hasDataCenterId()) {
assert drMap == null : drMap;
dataCenterId = opCtx.dataCenterId();
} else
dataCenterId = null;
assert keys0 != null;
if (log.isDebugEnabled())
log.debug(S.toString("Called removeAllAsync(...)", "tx", this, false, "keys", keys0, true, "implicit", implicit, false, "retval", retval, false));
try {
checkValid();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
if (F.isEmpty(keys0)) {
if (implicit()) {
try {
commit();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
}
return new GridFinishedFuture<>(ret.success(true));
}
init();
final Collection<KeyCacheObject> enlisted = new ArrayList<>();
ExpiryPolicy plc;
final CacheEntryPredicate[] filters = CU.filterArray(filter);
if (!F.isEmpty(filters))
plc = opCtx != null ? opCtx.expiry() : null;
else
plc = null;
final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
final IgniteInternalFuture<Void> loadFut = enlistWrite(cacheCtx, entryTopVer, keys0, plc, /*lookup map*/
null, /*invoke map*/
null, /*invoke arguments*/
null, retval, /*lock only*/
false, filters, ret, enlisted, null, drMap, opCtx != null && opCtx.skipStore(), singleRmv, keepBinary, opCtx != null && opCtx.recovery(), dataCenterId);
if (log.isDebugEnabled())
log.debug("Remove keys: " + enlisted);
// to be rolled back.
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 remove on keys: " + enlisted);
long timeout = remainingTime();
if (timeout == -1)
return new GridFinishedFuture<>(timeoutException());
IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, false, retval, isolation, isInvalidate(), -1L, -1L);
PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {
@Override
protected GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
if (log.isDebugEnabled())
log.debug("Acquired transaction lock for remove on keys: " + enlisted);
postLockWrite(cacheCtx, enlisted, ret, /*remove*/
true, retval, /*read*/
false, -1L, filters, /*computeInvoke*/
false);
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 {
if (implicit()) {
// with prepare response, if required.
assert loadFut.isDone();
return nonInterruptable(commitNearTxLocalAsync().chain(new CX1<IgniteInternalFuture<IgniteInternalTx>, GridCacheReturn>() {
@Override
public GridCacheReturn applyx(IgniteInternalFuture<IgniteInternalTx> txFut) throws IgniteCheckedException {
try {
txFut.get();
return new GridCacheReturn(cacheCtx, true, keepBinary, implicitRes.value(), implicitRes.success());
} catch (IgniteCheckedException | RuntimeException e) {
rollbackNearTxLocalAsync();
throw e;
}
}
}));
} else {
return nonInterruptable(loadFut.chain(new CX1<IgniteInternalFuture<Void>, GridCacheReturn>() {
@Override
public GridCacheReturn applyx(IgniteInternalFuture<Void> f) throws IgniteCheckedException {
f.get();
return ret;
}
}));
}
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridNearTxLocal method commitAsyncLocal.
/**
* Commits local part of colocated transaction.
*
* @return Commit future.
*/
public IgniteInternalFuture<IgniteInternalTx> commitAsyncLocal() {
if (log.isDebugEnabled())
log.debug("Committing colocated tx locally: " + this);
IgniteInternalFuture<?> prep = prepFut;
// Do not create finish future if there are no remote nodes.
if (F.isEmpty(dhtMap) && F.isEmpty(nearMap)) {
if (prep != null)
return (IgniteInternalFuture<IgniteInternalTx>) prep;
return new GridFinishedFuture<IgniteInternalTx>(this);
}
final GridDhtTxFinishFuture fut = new GridDhtTxFinishFuture<>(cctx, this, true);
cctx.mvcc().addFuture(fut, fut.futureId());
if (prep == null || prep.isDone()) {
assert prep != null || optimistic();
IgniteCheckedException err = null;
try {
if (prep != null)
// Check for errors of a parent future.
prep.get();
} catch (IgniteCheckedException e) {
err = e;
U.error(log, "Failed to prepare transaction: " + this, e);
}
if (err != null)
fut.rollbackOnError(err);
else
fut.finish(true);
} else
prep.listen(new CI1<IgniteInternalFuture<?>>() {
@Override
public void apply(IgniteInternalFuture<?> f) {
IgniteCheckedException err = null;
try {
// Check for errors of a parent future.
f.get();
} catch (IgniteCheckedException e) {
err = e;
U.error(log, "Failed to prepare transaction: " + this, e);
}
if (err != null)
fut.rollbackOnError(err);
else
fut.finish(true);
}
});
return fut;
}
Aggregations