use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.
the class GridNearOptimisticTxPrepareFuture method onError.
/**
* @param e Error.
* @param discoThread {@code True} if executed from discovery thread.
*/
private void onError(Throwable e, boolean discoThread) {
try (TraceSurroundings ignored = support(span)) {
if (e instanceof IgniteTxTimeoutCheckedException) {
onTimeout();
return;
}
if (X.hasCause(e, ClusterTopologyCheckedException.class) || X.hasCause(e, ClusterTopologyException.class)) {
if (tx.onePhaseCommit()) {
tx.markForBackupCheck();
onComplete();
return;
}
}
if (ERR_UPD.compareAndSet(this, null, e))
onComplete();
}
}
use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.
the class GridNearOptimisticTxPrepareFuture method onTimeout.
/**
*/
private void onTimeout() {
try (TraceSurroundings ignored = MTC.support(span)) {
if (cctx.tm().deadlockDetectionEnabled()) {
Set<IgniteTxKey> keys = null;
if (keyLockFut != null)
keys = new HashSet<>(keyLockFut.lockKeys);
else {
compoundsReadLock();
try {
int size = futuresCountNoLock();
for (int i = 0; i < size; i++) {
IgniteInternalFuture fut = future(i);
if (isMini(fut) && !fut.isDone()) {
MiniFuture miniFut = (MiniFuture) fut;
Collection<IgniteTxEntry> entries = miniFut.mapping().entries();
keys = U.newHashSet(entries.size());
for (IgniteTxEntry entry : entries) keys.add(entry.txKey());
break;
}
}
} finally {
compoundsReadUnlock();
}
}
add(new GridEmbeddedFuture<>(new IgniteBiClosure<TxDeadlock, Exception, Object>() {
@Override
public GridNearTxPrepareResponse apply(TxDeadlock deadlock, Exception e) {
if (e != null)
U.warn(log, "Failed to detect deadlock.", e);
else {
e = new IgniteTxTimeoutCheckedException("Failed to acquire lock within provided timeout for " + "transaction [timeout=" + tx.timeout() + ", tx=" + CU.txString(tx) + ']', deadlock != null ? new TransactionDeadlockException(deadlock.toString(cctx)) : null);
if (!ERR_UPD.compareAndSet(GridNearOptimisticTxPrepareFuture.this, null, e) && err instanceof IgniteTxTimeoutCheckedException) {
err = e;
}
}
onDone(null, e);
return null;
}
}, cctx.tm().detectDeadlock(tx, keys)));
} else {
ERR_UPD.compareAndSet(this, null, new IgniteTxTimeoutCheckedException("Failed to acquire lock " + "within provided timeout for transaction [timeout=" + tx.timeout() + ", tx=" + tx + ']'));
onComplete();
}
}
}
use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.
the class GridNearPessimisticTxPrepareFuture method prepare.
/**
* {@inheritDoc}
*/
@Override
public void prepare() {
try (TraceSurroundings ignored = MTC.supportContinual(span = cctx.kernalContext().tracing().create(TX_NEAR_PREPARE, MTC.span()))) {
if (!tx.state(PREPARING)) {
if (tx.isRollbackOnly() || tx.setRollbackOnly()) {
if (tx.remainingTime() == -1)
onDone(tx.timeoutException());
else
onDone(tx.rollbackException());
} else
onDone(new IgniteCheckedException("Invalid transaction state for prepare " + "[state=" + tx.state() + ", tx=" + this + ']'));
return;
}
try {
tx.userPrepare(Collections.<IgniteTxEntry>emptyList());
cctx.mvcc().addFuture(this);
preparePessimistic();
} catch (IgniteCheckedException e) {
onDone(e);
}
}
}
use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.
the class GridNearOptimisticSerializableTxPrepareFuture method onError.
/**
* @param m Failed mapping.
* @param e Error.
*/
private void onError(@Nullable GridDistributedTxMapping m, Throwable e) {
try (TraceSurroundings ignored = MTC.support(span)) {
if (X.hasCause(e, ClusterTopologyCheckedException.class) || X.hasCause(e, ClusterTopologyException.class)) {
if (tx.onePhaseCommit()) {
tx.markForBackupCheck();
onComplete();
return;
}
}
if (e instanceof IgniteTxOptimisticCheckedException) {
if (m != null)
tx.removeMapping(m.primary().id());
}
prepareError(e);
}
}
use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.
the class GridNearOptimisticTxPrepareFutureAdapter method prepare.
/**
* {@inheritDoc}
*/
@Override
public final void prepare() {
try (TraceSurroundings ignored = MTC.supportContinual(span = cctx.kernalContext().tracing().create(TX_NEAR_PREPARE, MTC.span()))) {
// Obtain the topology version to use.
long threadId = Thread.currentThread().getId();
AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(threadId);
// If there is another system transaction in progress, use it's topology version to prevent deadlock.
if (topVer == null && tx.system()) {
topVer = cctx.tm().lockedTopologyVersion(threadId, tx);
if (topVer == null)
topVer = tx.topologyVersionSnapshot();
}
if (topVer != null) {
tx.topologyVersion(topVer);
cctx.mvcc().addFuture(this);
prepare0(false, true);
return;
}
prepareOnTopology(false, null);
}
}
Aggregations