geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jche...@apache.org
Subject [geode] 01/01: Release server affinity immediately after commit
Date Fri, 01 Jun 2018 19:28:09 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit da24f81318fd280aaaa5d464ce4954ae38cbf302
Author: Michael Oleske <moleske@pivotal.io>
AuthorDate: Fri Jun 1 12:26:31 2018 -0700

    Release server affinity immediately after commit
    
    [GEODE-5277]
    
    Signed-off-by: Jianxia Chen <jchen@pivotal.io>
---
 .../geode/internal/cache/tx/ClientTXStateStub.java |  8 +++-
 .../internal/cache/tx/ClientTXStateStubTest.java   | 46 +++++++++++++++++++++-
 2 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
index 05f4b0b..c97d9f0 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tx/ClientTXStateStub.java
@@ -109,13 +109,17 @@ public class ClientTXStateStub extends TXStateStub {
   public void commit() throws CommitConflictException {
     obtainLocalLocks();
     try {
-      TXCommitMessage txcm = firstProxy.commit(proxy.getTxId().getUniqId());
+      TXCommitMessage txcm = null;
+      try {
+        txcm = firstProxy.commit(proxy.getTxId().getUniqId());
+      } finally {
+        this.firstProxy.getPool().releaseServerAffinity();
+      }
       afterServerCommit(txcm);
     } catch (TransactionDataNodeHasDepartedException e) {
       throw new TransactionInDoubtException(e);
     } finally {
       lockReq.releaseLocal();
-      this.firstProxy.getPool().releaseServerAffinity();
     }
   }
 
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tx/ClientTXStateStubTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/tx/ClientTXStateStubTest.java
index e6336ef..c178686 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tx/ClientTXStateStubTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tx/ClientTXStateStubTest.java
@@ -16,7 +16,10 @@ package org.apache.geode.internal.cache.tx;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
@@ -24,9 +27,11 @@ import static org.mockito.Mockito.when;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.mockito.InOrder;
 
 import org.apache.geode.CancelCriterion;
 import org.apache.geode.CancelException;
+import org.apache.geode.InternalGemFireError;
 import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.cache.client.internal.InternalPool;
 import org.apache.geode.cache.client.internal.ServerRegionProxy;
@@ -34,8 +39,10 @@ import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.internal.DistributionManager;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.TXCommitMessage;
 import org.apache.geode.internal.cache.TXId;
 import org.apache.geode.internal.cache.TXLockRequest;
+import org.apache.geode.internal.cache.TXManagerImpl;
 import org.apache.geode.internal.cache.TXRegionLockRequestImpl;
 import org.apache.geode.internal.cache.TXStateProxy;
 import org.apache.geode.test.junit.categories.UnitTest;
@@ -50,6 +57,7 @@ public class ClientTXStateStubTest {
   private LocalRegion region;
   private ServerRegionProxy serverRegionProxy;
   private CancelCriterion cancelCriterion;
+  private InternalPool internalPool;
 
   @Before
   public void setUp() {
@@ -59,10 +67,11 @@ public class ClientTXStateStubTest {
     target = mock(DistributedMember.class);
     region = mock(LocalRegion.class);
     serverRegionProxy = mock(ServerRegionProxy.class);
+    internalPool = mock(InternalPool.class);
     cancelCriterion = mock(CancelCriterion.class);
 
     when(region.getServerProxy()).thenReturn(serverRegionProxy);
-    when(serverRegionProxy.getPool()).thenReturn(mock(InternalPool.class));
+    when(serverRegionProxy.getPool()).thenReturn(internalPool);
     when(stateProxy.getTxId()).thenReturn(mock(TXId.class));
     when(cache.getCancelCriterion()).thenReturn(cancelCriterion);
     doThrow(new CacheClosedException()).when(cancelCriterion).checkCancelInProgress(any());
@@ -79,4 +88,39 @@ public class ClientTXStateStubTest {
     assertThatThrownBy(() -> stub.commit()).isInstanceOf(CancelException.class);
   }
 
+  @Test
+  public void commitReleasesServerAffinityAfterCommit() {
+    TXCommitMessage txCommitMessage = mock(TXCommitMessage.class);
+    TXManagerImpl txManager = mock(TXManagerImpl.class);
+    when(cache.getTxManager()).thenReturn(txManager);
+    when(serverRegionProxy.commit(anyInt())).thenReturn(txCommitMessage);
+
+    doNothing().when(cancelCriterion).checkCancelInProgress(null);
+    doNothing().when(txManager).setTXState(null);
+    ClientTXStateStub stub = spy(new ClientTXStateStub(cache, dm, stateProxy, target, region));
+
+    InOrder order = inOrder(serverRegionProxy, internalPool, cancelCriterion);
+    stub.commit();
+
+    order.verify(serverRegionProxy).commit(anyInt());
+    order.verify(internalPool).releaseServerAffinity();
+    order.verify(cancelCriterion).checkCancelInProgress(null);
+  }
+
+  @Test
+  public void commitReleasesServerAffinity_whenCommitThrowsAnException() {
+    TXManagerImpl txManager = mock(TXManagerImpl.class);
+    when(cache.getTxManager()).thenReturn(txManager);
+    when(serverRegionProxy.commit(anyInt())).thenThrow(new InternalGemFireError());
+
+    doNothing().when(cancelCriterion).checkCancelInProgress(null);
+    doNothing().when(txManager).setTXState(null);
+    ClientTXStateStub stub = spy(new ClientTXStateStub(cache, dm, stateProxy, target, region));
+
+    InOrder order = inOrder(serverRegionProxy, internalPool);
+    assertThatThrownBy(() -> stub.commit()).isInstanceOf(InternalGemFireError.class);
+
+    order.verify(serverRegionProxy).commit(anyInt());
+    order.verify(internalPool).releaseServerAffinity();
+  }
 }

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

Mime
View raw message