You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by es...@apache.org on 2018/06/11 18:21:00 UTC

[geode] branch feature/GEODE-5312 updated: GEDOE-5312: Cleanup transaction if it is removed by the client tx failover.

This is an automated email from the ASF dual-hosted git repository.

eshu11 pushed a commit to branch feature/GEODE-5312
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-5312 by this push:
     new 9229467  GEDOE-5312: Cleanup transaction if it is removed by the client tx failover.
9229467 is described below

commit 9229467845c544cbcf2ecfcb210f6ae365995743
Author: eshu <es...@pivotal.io>
AuthorDate: Mon Jun 11 11:16:58 2018 -0700

    GEDOE-5312: Cleanup transaction if it is removed by the client tx failover.
    
    Co-authored-by: Bradford D. Boyle <bb...@pivotal.io>
---
 .../apache/geode/internal/cache/TXManagerImpl.java | 17 ++++++++++++
 .../org/apache/geode/internal/cache/TXState.java   |  4 +++
 .../geode/internal/cache/TXManagerImplTest.java    | 30 ++++++++++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXManagerImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXManagerImpl.java
index efe1a10..193b3f1 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXManagerImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXManagerImpl.java
@@ -1017,11 +1017,24 @@ public class TXManagerImpl implements CacheTransactionManager, MembershipListene
    */
   public void unmasquerade(TXStateProxy tx) {
     if (tx != null) {
+      cleanupTransactionIfNotExist(tx);
       setTXState(null);
       tx.getLock().unlock();
     }
   }
 
+  private void cleanupTransactionIfNotExist(TXStateProxy tx) {
+    synchronized (hostedTXStates) {
+      if (!hostedTXStates.containsKey(tx.getTxId())) {
+        // clean up the transaction if no longer the host of the transaction
+        // this could occur when a failover command removed the transaction.
+        if (tx.isRealDealLocal()) {
+          ((TXStateProxyImpl) tx).getLocalRealDeal().cleanup();
+        }
+      }
+    }
+  }
+
   /**
    * Cleanup the remote txState after commit and rollback
    *
@@ -1858,4 +1871,8 @@ public class TXManagerImpl implements CacheTransactionManager, MembershipListene
     }
   }
 
+  Map<TXId, TXStateProxy> getHostedTXStates() {
+    return hostedTXStates;
+  }
+
 }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
index c321896..9768fb8 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXState.java
@@ -2064,4 +2064,8 @@ public class TXState implements TXStateInterface {
   public DistributedMember getProxyServer() {
     return this.proxyServer;
   }
+
+  boolean isClosed() {
+    return closed;
+  }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/TXManagerImplTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/TXManagerImplTest.java
index 7af4918..5731631 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/TXManagerImplTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/TXManagerImplTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 
 import java.util.concurrent.CountDownLatch;
@@ -337,4 +338,33 @@ public class TXManagerImplTest {
       txMgr.unmasquerade(existingTx);
     }
   }
+
+  @Test
+  public void txStateNotCleanedupIfNotRemovedFromHostedTxStatesMap() {
+    TXManagerImpl txManager = spy(txMgr);
+    tx1 = txManager.getOrSetHostedTXState(txid, msg);
+    TXStateProxyImpl txStateProxy = (TXStateProxyImpl) tx1;
+    assertNotNull(txStateProxy);
+    assertFalse(txStateProxy.getLocalRealDeal().isClosed());
+
+    txManager.masqueradeAs(tx1);
+    txManager.unmasquerade(tx1);
+    assertFalse(txStateProxy.getLocalRealDeal().isClosed());
+
+  }
+
+  @Test
+  public void txStateCleanedupIfRemovedFromHostedTxStatesMap() {
+    TXManagerImpl txManager = spy(txMgr);
+    tx1 = txManager.getOrSetHostedTXState(txid, msg);
+    TXStateProxyImpl txStateProxy = (TXStateProxyImpl) tx1;
+    assertNotNull(txStateProxy);
+    assertFalse(txStateProxy.getLocalRealDeal().isClosed());
+
+    txManager.masqueradeAs(tx1);
+    // during TX failover, tx can be removed from the hostedTXStates map by FindRemoteTXMessage
+    txManager.getHostedTXStates().remove(txid);
+    txManager.unmasquerade(tx1);
+    assertTrue(txStateProxy.getLocalRealDeal().isClosed());
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
eshu11@apache.org.