Repository: ignite
Updated Branches:
  refs/heads/master 8cb35e112 -> 10419a128


IGNITE-7844: Transaction incorrect state after client reconnect


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

Branch: refs/heads/master
Commit: 10419a128f4fbf7afa33e50a7d9a580e4eb1829e
Parents: 8cb35e1
Author: voipp <alkuznetsov...@gmail.com>
Authored: Thu May 17 12:34:39 2018 +0300
Committer: Nikolay Izhikov <nizhi...@apache.org>
Committed: Thu May 17 12:34:54 2018 +0300

----------------------------------------------------------------------
 .../cache/transactions/IgniteTxManager.java     | 15 ++++++-
 .../IgniteClientReconnectCacheTest.java         | 41 ++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/10419a12/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 dc8bc46..86360b6 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
@@ -114,6 +114,8 @@ 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;
 import static org.apache.ignite.transactions.TransactionState.SUSPENDED;
 import static org.apache.ignite.transactions.TransactionState.UNKNOWN;
 import static org.jsr166.ConcurrentLinkedHashMap.QueuePolicy.PER_SEGMENT_Q;
@@ -331,11 +333,20 @@ public class IgniteTxManager extends 
GridCacheSharedManagerAdapter {
     @Override public void onDisconnected(IgniteFuture reconnectFut) {
         txFinishSync.onDisconnected(reconnectFut);
 
-        for (IgniteInternalTx tx : idMap.values())
+        for (IgniteInternalTx tx : idMap.values()) {
             rollbackTx(tx, true, false);
-        for (IgniteInternalTx tx : nearIdMap.values())
+
+            tx.state(ROLLING_BACK);
+            tx.state(ROLLED_BACK);
+        }
+
+        for (IgniteInternalTx tx : nearIdMap.values()) {
             rollbackTx(tx, true, false);
 
+            tx.state(ROLLING_BACK);
+            tx.state(ROLLED_BACK);
+        }
+
         IgniteClientDisconnectedException err =
             new IgniteClientDisconnectedException(reconnectFut, "Client node 
disconnected.");
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/10419a12/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectCacheTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectCacheTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectCacheTest.java
index ec5eab2..3b578db 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectCacheTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/IgniteClientReconnectCacheTest.java
@@ -73,6 +73,8 @@ import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.testframework.GridTestUtils;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.apache.ignite.transactions.TransactionRollbackException;
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
@@ -389,6 +391,45 @@ public class IgniteClientReconnectCacheTest extends 
IgniteClientReconnectAbstrac
     /**
      * @throws Exception If failed.
      */
+    public void testTxStateAfterClientReconnect() throws Exception {
+        clientMode = true;
+
+        IgniteEx client = startGrid(SRV_CNT);
+
+        Ignite srv = ignite(0);
+
+        CacheConfiguration<Object, Object> ccfg = new 
CacheConfiguration<>(DEFAULT_CACHE_NAME);
+
+        ccfg.setAtomicityMode(TRANSACTIONAL);
+        ccfg.setCacheMode(PARTITIONED);
+        ccfg.setBackups(1);
+
+        IgniteCache<Object, Object> cache = client.getOrCreateCache(ccfg);
+
+        final IgniteTransactions txs = client.transactions();
+
+        for (TransactionConcurrency concurrency : 
TransactionConcurrency.values()) {
+            for (TransactionIsolation isolation : 
TransactionIsolation.values()) {
+                Transaction tx = txs.txStart(concurrency, isolation);
+
+                cache.put(1, 1);
+
+                reconnectClientNode(client, srv, null);
+
+                GridTestUtils.assertThrowsWithCause(() -> {
+                    tx.commit();
+
+                    return null;
+                }, TransactionRollbackException.class);
+            }
+        }
+
+        clientMode = false;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testReconnectTransactionInProgress1() throws Exception {
         clientMode = true;
 

Reply via email to