IGNITE-6181 wip.

Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ab4316ae
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ab4316ae
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ab4316ae

Branch: refs/heads/ignite-6181-1
Commit: ab4316ae965bb46af6521ff545956614b2dec62a
Parents: 0e2ff6a
Author: Aleksei Scherbakov <[email protected]>
Authored: Thu Sep 14 18:31:28 2017 +0300
Committer: Aleksei Scherbakov <[email protected]>
Committed: Thu Sep 14 18:31:28 2017 +0300

----------------------------------------------------------------------
 .../cache/distributed/near/GridNearTxLocal.java | 30 ++++++-----
 .../transactions/TxRollbackOnTimeoutTest.java   | 56 +++++++++++++++-----
 2 files changed, 61 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ab4316ae/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 ee3d1d9..0e75b69 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
@@ -3139,6 +3139,8 @@ public class GridNearTxLocal extends 
GridDhtTxLocalAdapter implements GridTimeou
         GridNearTxPrepareFutureAdapter fut = 
(GridNearTxPrepareFutureAdapter)prepFut;
 
         if (fut == null) {
+            removeTimeoutHandler();
+
             long timeout = remainingTime();
 
             // Future must be created before any exception can be thrown.
@@ -3163,8 +3165,6 @@ public class GridNearTxLocal extends 
GridDhtTxLocalAdapter implements GridTimeou
             // Prepare was called explicitly.
             return fut;
 
-        removeTimeoutHandler();
-
         mapExplicitLocks();
 
         fut.prepare();
@@ -3710,9 +3710,12 @@ public class GridNearTxLocal extends 
GridDhtTxLocalAdapter implements GridTimeou
 
         if (state != ROLLING_BACK && state != ROLLED_BACK && state != 
COMMITTING && state != COMMITTED)
             rollback();
-        else
+        else {
             cctx.tm().onLocalClose(this);
 
+            removeTimeoutHandler();
+        }
+
         synchronized (this) {
             try {
                 while (!done())
@@ -4023,10 +4026,10 @@ public class GridNearTxLocal extends 
GridDhtTxLocalAdapter implements GridTimeou
     }
 
     /**
-     * Removes timeout handler used for eager rollbacks on timeouts.
+     * Removes timeout handler.
      */
     private void removeTimeoutHandler() {
-        if (timeout() > 0 && !implicit() && !timedOut())
+        if (timeout() > 0 && !implicit())
             cctx.time().removeTimeoutObject(this);
     }
 
@@ -4037,12 +4040,12 @@ public class GridNearTxLocal extends 
GridDhtTxLocalAdapter implements GridTimeou
 
     /** {@inheritDoc} */
     @Override public long endTime() {
-        return startTime() + timeout() - 150;
+        return startTime() + timeout();
     }
 
     /** {@inheritDoc} */
     @Override public void onTimeout() {
-        //if (state(MARKED_ROLLBACK, true)) {
+        if (state(MARKED_ROLLBACK, true)) {
             cctx.kernalContext().closure().runLocalSafe(new Runnable() {
                 @Override public void run() {
                     // Wait for active local lock futures completion to 
prevent races with deadlock detection.
@@ -4060,15 +4063,16 @@ public class GridNearTxLocal extends 
GridDhtTxLocalAdapter implements GridTimeou
                         }
                     }
 
-                    if (state(MARKED_ROLLBACK, true)) {
-                        log().error("Transaction is timed out and will be 
rolled back [timeout=" + timeout() +
-                            ", tx=" + GridNearTxLocal.this + ']');
+                    if (state() != MARKED_ROLLBACK)
+                        return;
 
-                        rollbackNearTxLocalAsync();
-                    }
+                    log().error("Transaction is timed out and will be rolled 
back [timeout=" + timeout() +
+                        ", tx=" + GridNearTxLocal.this + ']');
+
+                    rollbackNearTxLocalAsync();
                 }
             });
-        //}
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/ab4316ae/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 025332ae..4bbff17 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
@@ -23,7 +23,6 @@ import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteSystemProperties;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
@@ -218,12 +217,43 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
      *
      * @throws Exception If failed.
      */
-    public void testDeadlockUnblockedOnTimeout() throws Exception {
+    public void testDeadlockUnblockedOnTimeout1() throws Exception {
         testDeadlockUnblockedOnTimeout0(ignite(0), ignite(1));
     }
 
     /**
      * Tests if deadlock is resolved on timeout with correct message.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDeadlockUnblockedOnTimeout2() throws Exception {
+        testDeadlockUnblockedOnTimeout0(ignite(0), ignite(0));
+    }
+
+    /**
+     * Tests if deadlock is resolved on timeout with correct message.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDeadlockUnblockedOnTimeout3() throws Exception {
+        Ignite client = startGrid("client");
+
+        testDeadlockUnblockedOnTimeout0(ignite(0), client);
+    }
+
+    /**
+     * Tests if deadlock is resolved on timeout with correct message.
+     *
+     * @throws Exception If failed.
+     */
+//    public void testDeadlockUnblockedOnTimeout4() throws Exception {
+//        Ignite client = startGrid("client");
+//
+//        testDeadlockUnblockedOnTimeout0(client, ignite(0));
+//    }
+
+    /**
+     * Tests if deadlock is resolved on timeout with correct message.
      * @throws Exception
      */
     private void testDeadlockUnblockedOnTimeout0(final Ignite node1, final 
Ignite node2) throws Exception {
@@ -232,7 +262,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {
                 try {
-                    try (Transaction tx = 
ignite(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 2)) {
+                    try (Transaction tx = 
node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, TX_TIMEOUT, 2)) {
                         node1.cache(CACHE_NAME).put(1, 1);
 
                         l.countDown();
@@ -253,7 +283,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
 
         IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
             @Override public void run() {
-                try (Transaction tx = 
ignite(1).transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 2)) {
+                try (Transaction tx = 
node2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, 0, 2)) {
                     node2.cache(CACHE_NAME).put(2, 2);
 
                     l.countDown();
@@ -346,6 +376,8 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     private void testTimeoutRemoval0(IgniteEx near, int mode, long timeout) 
throws Exception {
+        Throwable saved = null;
+
         try (Transaction tx = near.transactions().txStart(PESSIMISTIC, 
REPEATABLE_READ, timeout, 1)) {
             near.cache(CACHE_NAME).put(1, 1);
 
@@ -373,18 +405,18 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
                     fail();
             }
         }
-        catch (TransactionTimeoutException e) {
-            // No-op.
-        }
-        catch (CacheException e) {
-            assertTrue("Only timeout exception is possible", X.hasCause(e, 
TransactionTimeoutException.class));
+        catch (Throwable t) {
+            saved = t;
         }
 
         GridConcurrentSkipListSet set = 
U.field(near.context().cache().context().time(), "timeoutObjs");
 
         for (Object obj : set)
-            assertFalse("Not remove for mode=" + mode + " and timeout=" + 
timeout,
-                    obj.getClass().isAssignableFrom(GridNearTxLocal.class));
+            if (obj.getClass().isAssignableFrom(GridNearTxLocal.class)) {
+                log.error("Last saved exception", saved);
+
+                fail("Not remove for mode=" + mode + " and timeout=" + 
timeout);
+            }
     }
 
     /**
@@ -393,7 +425,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     private void testWaitingTxUnblockedOnTimeout0(final Ignite near, final 
Ignite other) throws Exception {
-        final int recordsCnt = 1;
+        final int recordsCnt = 100;
 
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {

Reply via email to