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/05/31 18:59:02 UTC

[geode] branch feature/GEODE-5271 updated: GEODE-5271: Throw TransactionDataRebalancedException during commit when bucket has been moved.

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

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


The following commit(s) were added to refs/heads/feature/GEODE-5271 by this push:
     new 921624b  GEODE-5271: Throw TransactionDataRebalancedException during commit when bucket has been moved.
921624b is described below

commit 921624b127bf71390d166c995ce726a67a86dc8c
Author: eshu <es...@pivotal.io>
AuthorDate: Thu May 31 11:57:26 2018 -0700

    GEODE-5271: Throw TransactionDataRebalancedException during commit when bucket has been moved.
    
    Co-authored-by: Ryan McMahon <rm...@pivotal.io>
---
 .../apache/geode/internal/cache/TXEntryState.java  |  5 ++
 .../org/apache/geode/internal/cache/TXState.java   |  2 +-
 .../geode/internal/cache/TXEntryStateTest.java     | 61 ++++++++++++++++++++++
 3 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/TXEntryState.java b/geode-core/src/main/java/org/apache/geode/internal/cache/TXEntryState.java
index 72a1b2d..49533eb 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/TXEntryState.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/TXEntryState.java
@@ -38,6 +38,7 @@ import org.apache.geode.cache.Operation;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionDestroyedException;
 import org.apache.geode.cache.TimeoutException;
+import org.apache.geode.cache.TransactionDataRebalancedException;
 import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
 import org.apache.geode.internal.Assert;
@@ -1460,6 +1461,10 @@ public class TXEntryState implements Releasable {
       }
     } catch (CacheRuntimeException ex) {
       r.getCancelCriterion().checkCancelInProgress(null);
+      if (ex instanceof RegionDestroyedException && r.isUsedForPartitionedRegionBucket()) {
+        throw new TransactionDataRebalancedException(
+            "Bucket rebalanced during commit: " + r.getFullPath(), ex);
+      }
       throw new CommitConflictException(
           LocalizedStrings.TXEntryState_CONFLICT_CAUSED_BY_CACHE_EXCEPTION.toLocalizedString(), ex);
     }
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..c1bec6b 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
@@ -708,7 +708,7 @@ public class TXState implements TXStateInterface {
                   r.getFullPath(), rde);
             }
             throw new TransactionDataRebalancedException(
-                "Bucket rebalanced during commit: " + r.getFullPath());
+                "Bucket rebalanced during commit: " + r.getFullPath(), rde);
           } finally {
             if (!lockObtained) {
               // fix for bug #41708 - unlock operation-locks already obtained
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/TXEntryStateTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/TXEntryStateTest.java
new file mode 100644
index 0000000..f2155af
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/TXEntryStateTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.geode.internal.cache;
+
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.cache.CacheRuntimeException;
+import org.apache.geode.cache.CommitConflictException;
+import org.apache.geode.cache.RegionDestroyedException;
+import org.apache.geode.cache.TransactionDataRebalancedException;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class TXEntryStateTest {
+
+  @Test(expected = TransactionDataRebalancedException.class)
+  public void checkConflictThrowsTransactionDataRebalancedExceptionIfBucketIsMoved() {
+    BucketRegion region = mock(BucketRegion.class);
+    TXEntryState txEntryState = spy(new TXEntryState());
+
+    when(region.isUsedForPartitionedRegionBucket()).thenReturn(true);
+    when(region.getCancelCriterion()).thenReturn(mock(CancelCriterion.class));
+    doThrow(new RegionDestroyedException("any", "any")).when(region).checkReadiness();
+
+    when(txEntryState.isDirty()).thenReturn(true);
+    txEntryState.checkForConflict(region, "anyKey");
+  }
+
+  @Test(expected = CommitConflictException.class)
+  public void checkConflictThrowsCommitConflictExceptionIfEncounterCacheRuntimeException() {
+    BucketRegion region = mock(BucketRegion.class);
+    TXEntryState txEntryState = spy(new TXEntryState());
+
+    when(region.getCancelCriterion()).thenReturn(mock(CancelCriterion.class));
+    when(region.basicGetEntry("key")).thenThrow(mock(CacheRuntimeException.class));
+
+    when(txEntryState.isDirty()).thenReturn(true);
+    txEntryState.checkForConflict(region, "key");
+  }
+
+}

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