Repository: ignite Updated Branches: refs/heads/ignite-2.5 acfef907d -> 6cea78e4e
IGNITE-7770 Test testRandomMixedTxConfigurations partialy fixed Signed-off-by: Andrey Gura <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6cea78e4 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6cea78e4 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6cea78e4 Branch: refs/heads/ignite-2.5 Commit: 6cea78e4e13fe43555b78dcd683366f54c6816ff Parents: acfef90 Author: Andrey Kuznetsov <[email protected]> Authored: Tue Apr 17 19:58:43 2018 +0300 Committer: Andrey Gura <[email protected]> Committed: Tue Apr 17 20:45:02 2018 +0300 ---------------------------------------------------------------------- .../processors/cache/GridCacheAdapter.java | 3 +- ...arOptimisticSerializableTxPrepareFuture.java | 2 +- .../near/GridNearOptimisticTxPrepareFuture.java | 2 +- .../GridNearPessimisticTxPrepareFuture.java | 2 +- .../near/GridNearTxFastFinishFuture.java | 10 ++-- .../cache/distributed/near/GridNearTxLocal.java | 57 +++++++++++++------- .../cache/transactions/IgniteTxManager.java | 5 +- .../transactions/TxRollbackOnTimeoutTest.java | 2 + 8 files changed, 55 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/6cea78e4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java index c2d0f42..bd613a1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java @@ -104,6 +104,7 @@ import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFi import org.apache.ignite.internal.processors.task.GridInternal; import org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException; import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException; +import org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException; import org.apache.ignite.internal.util.future.GridEmbeddedFuture; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.internal.util.future.GridFutureAdapter; @@ -4283,7 +4284,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V } catch (IgniteCheckedException e1) { try { - tx0.rollbackNearTxLocalAsync(); + tx0.rollbackNearTxLocalAsync(e1 instanceof IgniteTxTimeoutCheckedException); } catch (Throwable e2) { if (e2 != e1) http://git-wip-us.apache.org/repos/asf/ignite/blob/6cea78e4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java index beb1e16..3e2c84a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticSerializableTxPrepareFuture.java @@ -294,7 +294,7 @@ public class GridNearOptimisticSerializableTxPrepareFuture extends GridNearOptim boolean txStateCheck = remap ? tx.state() == PREPARING : tx.state(PREPARING); if (!txStateCheck) { - if (tx.setRollbackOnly()) { + if (tx.isRollbackOnly() || tx.setRollbackOnly()) { if (tx.timedOut()) onError(null, new IgniteTxTimeoutCheckedException("Transaction timed out and " + "was rolled back: " + this)); http://git-wip-us.apache.org/repos/asf/ignite/blob/6cea78e4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java index 8d8c0b2..2afb096 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearOptimisticTxPrepareFuture.java @@ -327,7 +327,7 @@ public class GridNearOptimisticTxPrepareFuture extends GridNearOptimisticTxPrepa boolean txStateCheck = remap ? tx.state() == PREPARING : tx.state(PREPARING); if (!txStateCheck) { - if (tx.setRollbackOnly()) { + if (tx.isRollbackOnly() || tx.setRollbackOnly()) { if (tx.remainingTime() == -1) onError(new IgniteTxTimeoutCheckedException("Transaction timed out and " + "was rolled back: " + this), false); http://git-wip-us.apache.org/repos/asf/ignite/blob/6cea78e4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java index 4ab6863..54ae85c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearPessimisticTxPrepareFuture.java @@ -155,7 +155,7 @@ public class GridNearPessimisticTxPrepareFuture extends GridNearTxPrepareFutureA /** {@inheritDoc} */ @Override public void prepare() { if (!tx.state(PREPARING)) { - if (tx.setRollbackOnly()) { + if (tx.isRollbackOnly() || tx.setRollbackOnly()) { if (tx.remainingTime() == -1) onDone(new IgniteTxTimeoutCheckedException("Transaction timed out and was rolled back: " + tx)); else http://git-wip-us.apache.org/repos/asf/ignite/blob/6cea78e4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFastFinishFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFastFinishFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFastFinishFuture.java index 7222697..95e4ded 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFastFinishFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxFastFinishFuture.java @@ -37,13 +37,17 @@ public class GridNearTxFastFinishFuture extends GridFutureAdapter<IgniteInternal /** */ private final boolean commit; + /** */ + private final boolean onTimeout; + /** * @param tx Transaction. * @param commit Commit flag. */ - GridNearTxFastFinishFuture(GridNearTxLocal tx, boolean commit) { + GridNearTxFastFinishFuture(GridNearTxLocal tx, boolean commit, boolean onTimeout) { this.tx = tx; this.commit = commit; + this.onTimeout = onTimeout; } /** {@inheritDoc} */ @@ -61,7 +65,7 @@ public class GridNearTxFastFinishFuture extends GridFutureAdapter<IgniteInternal tx.state(PREPARED); tx.state(COMMITTING); - tx.context().tm().fastFinishTx(tx, true); + tx.context().tm().fastFinishTx(tx, true, true); tx.state(COMMITTED); } @@ -70,7 +74,7 @@ public class GridNearTxFastFinishFuture extends GridFutureAdapter<IgniteInternal tx.state(PREPARED); tx.state(ROLLING_BACK); - tx.context().tm().fastFinishTx(tx, false); + tx.context().tm().fastFinishTx(tx, false, !onTimeout); tx.state(ROLLED_BACK); } http://git-wip-us.apache.org/repos/asf/ignite/blob/6cea78e4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java index fc8a9a3..e339750 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java @@ -111,6 +111,7 @@ import static org.apache.ignite.internal.processors.cache.transactions.IgniteTxE import static org.apache.ignite.transactions.TransactionState.COMMITTED; import static org.apache.ignite.transactions.TransactionState.COMMITTING; import static org.apache.ignite.transactions.TransactionState.MARKED_ROLLBACK; +import static org.apache.ignite.transactions.TransactionState.PREPARED; import static org.apache.ignite.transactions.TransactionState.PREPARING; import static org.apache.ignite.transactions.TransactionState.ROLLED_BACK; import static org.apache.ignite.transactions.TransactionState.ROLLING_BACK; @@ -165,7 +166,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou protected boolean transform; /** */ - private boolean trackTimeout; + private final boolean trackTimeout; /** */ @GridToStringExclude @@ -175,7 +176,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou * Empty constructor required for {@link Externalizable}. */ public GridNearTxLocal() { - // No-op. + this.trackTimeout = false; } /** @@ -228,8 +229,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou initResult(); - if (timeout() > 0 && !implicit()) - trackTimeout = cctx.time().addTimeoutObject(this); + trackTimeout = timeout() > 0 && !implicit() && cctx.time().addTimeoutObject(this); } /** {@inheritDoc} */ @@ -3155,8 +3155,13 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou if (!PREP_FUT_UPD.compareAndSet(this, null, fut)) return prepFut; - if (trackTimeout) - removeTimeoutHandler(); + if (trackTimeout) { + prepFut.listen(new IgniteInClosure<IgniteInternalFuture<?>>() { + @Override public void apply(IgniteInternalFuture<?> f) { + GridNearTxLocal.this.removeTimeoutHandler(); + } + }); + } if (timeout == -1) { fut.onDone(this, timeoutException()); @@ -3215,7 +3220,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou if (fastFinish()) { GridNearTxFastFinishFuture fut0; - if (!FINISH_FUT_UPD.compareAndSet(this, null, fut0 = new GridNearTxFastFinishFuture(this, true))) + if (!FINISH_FUT_UPD.compareAndSet(this, null, fut0 = new GridNearTxFastFinishFuture(this, true, false))) return chainFinishFuture(finishFut, true); fut0.finish(); @@ -3238,7 +3243,9 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou // Make sure that here are no exceptions. prepareFut.get(); - fut0.finish(true, true); + TransactionState state = state(); + + fut0.finish(state == PREPARED || state == COMMITTING || state == COMMITTED, true); } catch (Error | RuntimeException e) { COMMIT_ERR_UPD.compareAndSet(GridNearTxLocal.this, null, e); @@ -3282,7 +3289,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou * @param onTimeout {@code True} if rolled back asynchronously on timeout. * @return Rollback future. */ - private IgniteInternalFuture<IgniteInternalTx> rollbackNearTxLocalAsync(final boolean onTimeout) { + public IgniteInternalFuture<IgniteInternalTx> rollbackNearTxLocalAsync(final boolean onTimeout) { if (log.isDebugEnabled()) log.debug("Rolling back near tx: " + this); @@ -3292,13 +3299,13 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou NearTxFinishFuture fut = finishFut; if (fut != null) - return chainFinishFuture(finishFut, false); + return chainFinishFuture(finishFut, false, !onTimeout); if (fastFinish()) { GridNearTxFastFinishFuture fut0; - if (!FINISH_FUT_UPD.compareAndSet(this, null, fut0 = new GridNearTxFastFinishFuture(this, false))) - return chainFinishFuture(finishFut, false); + if (!FINISH_FUT_UPD.compareAndSet(this, null, fut0 = new GridNearTxFastFinishFuture(this, false, onTimeout))) + return chainFinishFuture(finishFut, false, !onTimeout); fut0.finish(); @@ -3308,7 +3315,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou final GridNearTxFinishFuture fut0; if (!FINISH_FUT_UPD.compareAndSet(this, null, fut0 = new GridNearTxFinishFuture<>(cctx, this, false))) - return chainFinishFuture(finishFut, false); + return chainFinishFuture(finishFut, false, !onTimeout); cctx.mvcc().addFuture(fut0, fut0.futureId()); @@ -3327,7 +3334,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou fut0.finish(false, !onTimeout); } - else { + else if (!onTimeout) { prepFut.listen(new CI1<IgniteInternalFuture<?>>() { @Override public void apply(IgniteInternalFuture<?> f) { try { @@ -3339,10 +3346,11 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou log.debug("Got optimistic tx failure [tx=" + this + ", err=" + e + ']'); } - fut0.finish(false, !onTimeout); + fut0.finish(false, true); } }); - } + } else + fut0.finish(false, false); return fut0; } @@ -3352,12 +3360,17 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou return rollbackNearTxLocalAsync(); } + /** */ + private IgniteInternalFuture<IgniteInternalTx> chainFinishFuture(final NearTxFinishFuture fut, final boolean commit) { + return chainFinishFuture(fut, commit, true); + } + /** * @param fut Already started finish future. * @param commit Commit flag. * @return Finish future. */ - private IgniteInternalFuture<IgniteInternalTx> chainFinishFuture(final NearTxFinishFuture fut, final boolean commit) { + private IgniteInternalFuture<IgniteInternalTx> chainFinishFuture(final NearTxFinishFuture fut, final boolean commit, final boolean clearThreadMap) { assert fut != null; if (fut.commit() != commit) { @@ -3381,7 +3394,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou if (!cctx.mvcc().addFuture(rollbackFut, rollbackFut.futureId())) return; - rollbackFut.finish(false, true); + rollbackFut.finish(false, clearThreadMap); } } } @@ -4161,7 +4174,13 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter implements GridTimeou } } - if (state(MARKED_ROLLBACK, true) || (state() == MARKED_ROLLBACK)) { + boolean proceed; + + synchronized (this) { + proceed = state() != PREPARED && state(MARKED_ROLLBACK, true); + } + + if (proceed || (state() == MARKED_ROLLBACK)) { cctx.kernalContext().closure().runLocalSafe(new Runnable() { @Override public void run() { // Note: if rollback asynchronously on timeout should not clear thread map http://git-wip-us.apache.org/repos/asf/ignite/blob/6cea78e4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java index 9fb8777..7fa31bf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java @@ -1356,7 +1356,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter { * @param tx Transaction to finish. * @param commit {@code True} if transaction is committed, {@code false} if rolled back. */ - public void fastFinishTx(GridNearTxLocal tx, boolean commit) { + public void fastFinishTx(GridNearTxLocal tx, boolean commit, boolean clearThreadMap) { assert tx != null; assert tx.writeMap().isEmpty(); assert tx.optimistic() || tx.readMap().isEmpty(); @@ -1377,7 +1377,8 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter { removeObsolete(tx); // 4. Remove from per-thread storage. - clearThreadMap(tx); + if (clearThreadMap) + clearThreadMap(tx); // 5. Clear context. resetContext(); http://git-wip-us.apache.org/repos/asf/ignite/blob/6cea78e4/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java index c5be40e..97de81e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java @@ -439,6 +439,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest { if (delay > 0) sleep(delay); + assert v != null; + node.cache(CACHE_NAME).put(k, v + 1); tx.commit();
