use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridCachePartitionExchangeManager method dumpPendingObjects.
/**
* @param exchTopVer Exchange topology version.
*/
private void dumpPendingObjects(@Nullable AffinityTopologyVersion exchTopVer) {
IgniteTxManager tm = cctx.tm();
if (tm != null) {
U.warn(log, "Pending transactions:");
for (IgniteInternalTx tx : tm.activeTransactions()) {
if (exchTopVer != null) {
U.warn(log, ">>> [txVer=" + tx.topologyVersionSnapshot() + ", exchWait=" + tm.needWaitTransaction(tx, exchTopVer) + ", tx=" + tx + ']');
} else
U.warn(log, ">>> [txVer=" + tx.topologyVersionSnapshot() + ", tx=" + tx + ']');
}
}
GridCacheMvccManager mvcc = cctx.mvcc();
if (mvcc != null) {
U.warn(log, "Pending explicit locks:");
for (GridCacheExplicitLockSpan lockSpan : mvcc.activeExplicitLocks()) U.warn(log, ">>> " + lockSpan);
U.warn(log, "Pending cache futures:");
for (GridCacheFuture<?> fut : mvcc.activeFutures()) U.warn(log, ">>> " + fut);
U.warn(log, "Pending atomic cache futures:");
for (GridCacheFuture<?> fut : mvcc.atomicFutures()) U.warn(log, ">>> " + fut);
U.warn(log, "Pending data streamer futures:");
for (IgniteInternalFuture<?> fut : mvcc.dataStreamerFutures()) U.warn(log, ">>> " + fut);
if (tm != null) {
U.warn(log, "Pending transaction deadlock detection futures:");
for (IgniteInternalFuture<?> fut : tm.deadlockDetectionFutures()) U.warn(log, ">>> " + fut);
}
}
for (GridCacheContext ctx : cctx.cacheContexts()) {
if (ctx.isLocal())
continue;
GridCacheContext ctx0 = ctx.isNear() ? ctx.near().dht().context() : ctx;
GridCachePreloader preloader = ctx0.preloader();
if (preloader != null)
preloader.dumpDebugInfo();
GridCacheAffinityManager affMgr = ctx0.affinity();
if (affMgr != null)
affMgr.dumpDebugInfo();
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.
the class GridDhtTxPrepareFuture method onDone.
/** {@inheritDoc} */
@Override
public boolean onDone(GridNearTxPrepareResponse res0, Throwable err) {
assert err != null || (initialized() && !hasPending()) : "On done called for prepare future that has " + "pending mini futures: " + this;
ERR_UPD.compareAndSet(this, null, err);
// Must clear prepare future before response is sent or listeners are notified.
if (tx.optimistic())
tx.clearPrepareFuture(this);
// Do not commit one-phase commit transaction if originating node has near cache enabled.
if (tx.onePhaseCommit() && tx.commitOnPrepare()) {
assert last;
Throwable prepErr = this.err;
// Must create prepare response before transaction is committed to grab correct return value.
final GridNearTxPrepareResponse res = createPrepareResponse(prepErr);
onComplete(res);
if (tx.commitOnPrepare()) {
if (tx.markFinalizing(IgniteInternalTx.FinalizationStatus.USER_FINISH)) {
IgniteInternalFuture<IgniteInternalTx> fut = null;
CIX1<IgniteInternalFuture<IgniteInternalTx>> resClo = new CIX1<IgniteInternalFuture<IgniteInternalTx>>() {
@Override
public void applyx(IgniteInternalFuture<IgniteInternalTx> fut) {
if (REPLIED_UPD.compareAndSet(GridDhtTxPrepareFuture.this, 0, 1))
sendPrepareResponse(res);
}
};
if (prepErr == null) {
try {
fut = tx.commitAsync();
} catch (RuntimeException | Error e) {
Exception hEx = new IgniteTxHeuristicCheckedException("Commit produced a runtime " + "exception: " + CU.txString(tx), e);
res.error(hEx);
tx.systemInvalidate(true);
fut = tx.rollbackAsync();
fut.listen(resClo);
throw e;
}
} else if (!cctx.kernalContext().isStopping())
fut = tx.rollbackAsync();
if (fut != null)
fut.listen(resClo);
}
} else {
if (REPLIED_UPD.compareAndSet(this, 0, 1))
sendPrepareResponse(res);
}
return true;
} else {
if (REPLIED_UPD.compareAndSet(this, 0, 1)) {
GridNearTxPrepareResponse res = createPrepareResponse(this.err);
try {
sendPrepareResponse(res);
} finally {
// Will call super.onDone().
onComplete(res);
}
return true;
} else {
// Other thread is completing future. Wait for it to complete.
try {
if (err != null)
get();
} catch (IgniteInterruptedException e) {
onError(new IgniteCheckedException("Got interrupted while waiting for replies to be sent.", e));
} catch (IgniteCheckedException ignored) {
// No-op, get() was just synchronization.
}
return false;
}
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx 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.processors.cache.transactions.IgniteInternalTx 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.processors.cache.transactions.IgniteInternalTx 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