This is an automated email from the ASF dual-hosted git repository. eshu11 pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push: new ca1f3bf GEODE-5312: Cleanup transaction if it is removed by the client tx failover (#2047) ca1f3bf is described below commit ca1f3bf8dd58c610766c3a585649ed90cccbe607 Author: pivotal-eshu <e...@pivotal.io> AuthorDate: Mon Jun 11 15:39:21 2018 -0700 GEODE-5312: Cleanup transaction if it is removed by the client tx failover (#2047) * GEODE-5312: Cleanup transaction if it is removed by the client tx failover. --- .../apache/geode/internal/cache/TXManagerImpl.java | 17 ++++++++++++++ .../org/apache/geode/internal/cache/TXState.java | 4 ++++ .../geode/internal/cache/TXManagerImplTest.java | 27 ++++++++++++++++++++++ 3 files changed, 48 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..c5c7653 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) { + cleanupTransactionIfNoLongerHost(tx); setTXState(null); tx.getLock().unlock(); } } + private void cleanupTransactionIfNoLongerHost(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..cdbc763 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 @@ -337,4 +337,31 @@ public class TXManagerImplTest { txMgr.unmasquerade(existingTx); } } + + @Test + public void txStateNotCleanedupIfNotRemovedFromHostedTxStatesMap() { + tx1 = txMgr.getOrSetHostedTXState(txid, msg); + TXStateProxyImpl txStateProxy = (TXStateProxyImpl) tx1; + assertNotNull(txStateProxy); + assertFalse(txStateProxy.getLocalRealDeal().isClosed()); + + txMgr.masqueradeAs(tx1); + txMgr.unmasquerade(tx1); + assertFalse(txStateProxy.getLocalRealDeal().isClosed()); + + } + + @Test + public void txStateCleanedupIfRemovedFromHostedTxStatesMap() { + tx1 = txMgr.getOrSetHostedTXState(txid, msg); + TXStateProxyImpl txStateProxy = (TXStateProxyImpl) tx1; + assertNotNull(txStateProxy); + assertFalse(txStateProxy.getLocalRealDeal().isClosed()); + + txMgr.masqueradeAs(tx1); + // during TX failover, tx can be removed from the hostedTXStates map by FindRemoteTXMessage + txMgr.getHostedTXStates().remove(txid); + txMgr.unmasquerade(tx1); + assertTrue(txStateProxy.getLocalRealDeal().isClosed()); + } } -- To stop receiving notification emails like this one, please contact esh...@apache.org.