@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); } } });
@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); } } });
/** {@inheritDoc} */ @Override public boolean setRollbackOnly() { enter(); try { return tx.setRollbackOnly(); } finally { leave(); } }
@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); } } });
/** * @param e Error. */ void onError(Throwable e) { if (isDone()) { U.warn(log, "Received error when future is done [fut=" + this + ", err=" + e + ", tx=" + tx + ']'); return; } if (log.isDebugEnabled()) log.debug("Error on tx prepare [fut=" + this + ", err=" + e + ", tx=" + tx + ']'); if (ERR_UPD.compareAndSet(GridNearPessimisticTxPrepareFuture.this, null, e)) tx.setRollbackOnly(); onDone(e); }
/** {@inheritDoc} */ @Override public boolean onDone(@Nullable Long res, @Nullable Throwable err, boolean cancelled) { if (!DONE_UPD.compareAndSet(this, 0, 1)) return false; cctx.tm().resetContext(); Throwable ex0 = ex; if (ex0 != null) { if (err != null) ex0.addSuppressed(err); err = ex0; } if (!cancelled && err == null) tx.clearLockFuture(this); else tx.setRollbackOnly(); boolean done = super.onDone(res, err, cancelled); assert done; // Clean up. cctx.mvcc().removeVersionedFuture(this); if (timeoutObj != null) cctx.time().removeTimeoutObject(timeoutObj); return true; }
/** {@inheritDoc} */ @Override public void end(Xid xid, int flags) throws XAException { assert this.xid.equals(xid); if (log.isDebugEnabled()) log.debug("XA resource end(...) [xid=" + xid + ", flags=<" + flags(flags) + ">]"); if ((flags & TMFAIL) > 0) cacheTx.setRollbackOnly(); else if ((flags & TMSUSPEND) == TMSUSPEND) { try { cacheTx.suspend(); } catch (IgniteCheckedException e) { throwException("Failed to suspend cache transaction: " + e.getMessage(), e); } } }
/** {@inheritDoc} */ @Override public final T apply(T t, @Nullable Exception e) { boolean rollback = true; try { if (e != null) throw new GridClosureException(e); t = finish(t); // Commit implicit transactions. if (implicit()) commit(); rollback = false; return t; } catch (IgniteCheckedException ex) { throw new GridClosureException(ex); } finally { if (rollback) setRollbackOnly(); } }
/** * @param ctx Grid kernal context. * @param txId Transaction ID. * @return Currently started user transaction, or {@code null} if none started. * @throws UnsupportedTxModeException If transaction mode is not supported when MVCC is enabled. * @throws NonMvccTransactionException If started transaction spans non MVCC caches. */ @Nullable public static GridNearTxLocal currentTx(GridKernalContext ctx, @Nullable GridCacheVersion txId) throws UnsupportedTxModeException, NonMvccTransactionException { IgniteTxManager tm = ctx.cache().context().tm(); IgniteInternalTx tx0 = txId == null ? tm.tx() : tm.tx(txId); GridNearTxLocal tx = tx0 != null && tx0.user() ? (GridNearTxLocal)tx0 : null; if (tx != null) { if (!tx.pessimistic()) { tx.setRollbackOnly(); throw new UnsupportedTxModeException(); } if (!tx.isOperationAllowed(true)) { tx.setRollbackOnly(); throw new NonMvccTransactionException(); } } return tx; }
tx.clearLockFuture(this); else tx.setRollbackOnly();
@Override public Map<K, V> apply(Void v, Exception e) { if (e != null) { setRollbackOnly(); throw new GridClosureException(e); } if (isRollbackOnly()) { if (timedOut()) throw new GridClosureException(new IgniteTxTimeoutCheckedException( "Transaction has been timed out: " + GridNearTxLocal.this)); else throw new GridClosureException(new IgniteTxRollbackCheckedException( "Transaction has been rolled back: " + GridNearTxLocal.this)); } return map; } },
boolean marked = tx.setRollbackOnly();
/** * Undoes all locks. * * @param dist If {@code true}, then remove locks from remote nodes as well. * @param rollback {@code True} if should rollback tx. */ private void undoLocks(boolean dist, boolean rollback) { // Transactions will undo during rollback. if (dist && tx == null) cctx.colocated().removeLocks(threadId, lockVer, keys); else { if (rollback && tx != null) { if (tx.setRollbackOnly()) { if (log.isDebugEnabled()) log.debug("Marked transaction as rollback only because locks could not be acquired: " + tx); } else if (log.isDebugEnabled()) log.debug("Transaction was not marked rollback-only while locks were not acquired: " + tx); } } cctx.mvcc().recheckPendingLocks(); }
/** * Completeness callback. * * @return {@code True} if future was finished by this call. */ private boolean onComplete() { Throwable err0 = err; if ((!tx.onePhaseCommit() || tx.mappings().get(cctx.localNodeId()) == null) && (err0 == null || tx.needCheckBackup())) tx.state(PREPARED); if (super.onDone(tx, err0)) { if (err0 != null) tx.setRollbackOnly(); // Don't forget to clean up. cctx.mvcc().removeVersionedFuture(this); return true; } return false; }
/** {@inheritDoc} */ @Override public void prepare() { 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); } }
@Override public GridNearTxPrepareResponse apply(IgniteInternalFuture<GridNearTxPrepareResponse> f) { try { return f.get(); } catch (Exception e) { locTx.setRollbackOnly(); // Just in case. if (!X.hasCause(e, IgniteTxOptimisticCheckedException.class) && !X.hasCause(e, IgniteFutureCancelledException.class)) U.error(log, "Failed to prepare DHT transaction: " + locTx, e); return new GridNearTxPrepareResponse( req.partition(), req.version(), req.futureId(), req.miniId(), req.version(), req.version(), null, e, null, req.onePhaseCommit(), req.deployInfo() != null); } } });
return new GridFinishedFuture<>(timeoutException()); setRollbackOnly(); setRollbackOnly();
if (tx.isRollbackOnly() || tx.setRollbackOnly()) { if (tx.remainingTime() == -1) onDone(tx.timeoutException());
else { if (rollback && tx != null) { if (tx.setRollbackOnly()) { if (log.isDebugEnabled()) log.debug("Marked transaction as rollback only because locks could not be acquired: " + tx);
/** * Initializes future. * * @param remap Remap flag. */ @Override protected void prepare0(boolean remap, boolean topLocked) { boolean txStateCheck = remap ? tx.state() == PREPARING : tx.state(PREPARING); if (!txStateCheck) { if (tx.isRollbackOnly() || tx.setRollbackOnly()) { if (tx.timedOut()) onDone(null, tx.timeoutException()); else onDone(null, tx.rollbackException()); } else onDone(null, new IgniteCheckedException("Invalid transaction state for " + "prepare [state=" + tx.state() + ", tx=" + this + ']')); return; } boolean set = cctx.tm().setTxTopologyHint(tx.topologyVersionSnapshot()); try { prepare(tx.readEntries(), tx.writeEntries(), remap, topLocked); markInitialized(); } finally { if (set) cctx.tm().setTxTopologyHint(null); } }