You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/05/27 19:58:56 UTC

[GitHub] [geode] pivotal-eshu opened a new pull request, #7738: GEODE-10294: Compare invalid token during putIfAbsent retry.

pivotal-eshu opened a new pull request, #7738:
URL: https://github.com/apache/geode/pull/7738

    * During putIfAbsent retry, comparing invalid token value when
      putIfAbsent of a null value instead.
    * Do not make putIfAbsent event to update event if current
      entry value is null or invalidate.
   
   <!-- Thank you for submitting a contribution to Apache Geode. -->
   
   <!-- In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken: 
   -->
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   <!-- Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [geode] dschneider-pivotal commented on a diff in pull request #7738: GEODE-10294: Compare invalid token during putIfAbsent retry.

Posted by GitBox <gi...@apache.org>.
dschneider-pivotal commented on code in PR #7738:
URL: https://github.com/apache/geode/pull/7738#discussion_r886181394


##########
geode-core/src/main/java/org/apache/geode/internal/cache/map/RegionMapPut.java:
##########
@@ -430,6 +432,16 @@ private boolean checkCreatePreconditions() {
     return true;
   }
 
+  private boolean isSameValueAlreadyInCacheForPutIfAbsent(Object retainedValue) {

Review Comment:
   In this method add a local: Object rawNewValue = getEvent().getRawNewValue();
   so that getRawNewValue() will only be called once.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [geode] pivotal-eshu merged pull request #7738: GEODE-10294: Compare invalid token during putIfAbsent retry.

Posted by GitBox <gi...@apache.org>.
pivotal-eshu merged PR #7738:
URL: https://github.com/apache/geode/pull/7738


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [geode] pivotal-jbarrett commented on a diff in pull request #7738: GEODE-10294: Compare invalid token during putIfAbsent retry.

Posted by GitBox <gi...@apache.org>.
pivotal-jbarrett commented on code in PR #7738:
URL: https://github.com/apache/geode/pull/7738#discussion_r886192747


##########
geode-core/src/integrationTest/java/org/apache/geode/cache/RetryPutIfAbsentIntegrationTest.java:
##########
@@ -14,73 +14,94 @@
  */
 package org.apache.geode.cache;
 
-import static org.apache.geode.internal.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import org.apache.geode.cache.query.CacheUtils;
+import org.apache.geode.cache.util.CacheListenerAdapter;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
 import org.apache.geode.internal.cache.EventID;
 import org.apache.geode.internal.cache.EventIDHolder;
 import org.apache.geode.internal.cache.LocalRegion;
 import org.apache.geode.internal.cache.VMCachedDeserializable;
 import org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID;
 
-public class RetryPutIfAbsentIntegrationTest {
+class RetryPutIfAbsentIntegrationTest {

Review Comment:
   Thanks for the conversion to JUnit 5.



##########
geode-core/src/integrationTest/java/org/apache/geode/cache/RetryPutIfAbsentIntegrationTest.java:
##########
@@ -14,73 +14,94 @@
  */
 package org.apache.geode.cache;
 
-import static org.apache.geode.internal.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import org.apache.geode.cache.query.CacheUtils;
+import org.apache.geode.cache.util.CacheListenerAdapter;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
 import org.apache.geode.internal.cache.EventID;
 import org.apache.geode.internal.cache.EventIDHolder;
 import org.apache.geode.internal.cache.LocalRegion;
 import org.apache.geode.internal.cache.VMCachedDeserializable;
 import org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID;
 
-public class RetryPutIfAbsentIntegrationTest {
+class RetryPutIfAbsentIntegrationTest {
 
-  Cache cache;
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
+  private Cache cache;
+  private LocalRegion myRegion;
+  private final ClientProxyMembershipID id =
+      new ClientProxyMembershipID(new InternalDistributedMember("localhost", 1));
+  private final EventIDHolder clientEvent =
+      new EventIDHolder(new EventID(new byte[] {1, 2, 3, 4, 5}, 1, 1));
+  private final String key = "key";
+  private int updateCount;
 
   @Test
-  public void duplicatePutIfAbsentIsAccepted() {
-    final String key = "mykey";
-    final String value = "myvalue";
-
-    LocalRegion myregion =
-        (LocalRegion) CacheUtils.getCache().createRegionFactory(RegionShortcut.REPLICATE)
-            .setConcurrencyChecksEnabled(true).create("myregion");
-
-    ClientProxyMembershipID id =
-        new ClientProxyMembershipID(new InternalDistributedMember("localhost", 1));
-    EventIDHolder clientEvent = new EventIDHolder(new EventID(new byte[] {1, 2, 3, 4, 5}, 1, 1));
-    clientEvent.setRegion(myregion);
-    byte[] valueBytes = new VMCachedDeserializable("myvalue", 7).getSerializedValue();
+  void duplicatePutIfAbsentIsAccepted() {
+    myRegion = (LocalRegion) cache.createRegionFactory(RegionShortcut.REPLICATE)
+        .setConcurrencyChecksEnabled(true).create("myRegion");
+
+    clientEvent.setRegion(myRegion);
+    byte[] valueBytes = new VMCachedDeserializable("myValue", 7).getSerializedValue();
     System.out.println("first putIfAbsent");
     Object oldValue =
-        myregion.basicBridgePutIfAbsent("mykey", valueBytes, true, null, id, true, clientEvent);
-    assertEquals(null, oldValue);
-    assertTrue(myregion.containsKey(key));
+        myRegion.basicBridgePutIfAbsent(key, valueBytes, true, null, id, true, clientEvent);
+    assertThat(oldValue).isNull();
+    assertThat(myRegion.containsKey(key)).isTrue();
 
-    myregion.getEventTracker().clear();
+    myRegion.getEventTracker().clear();
 
-    clientEvent = new EventIDHolder(new EventID(new byte[] {1, 2, 3, 4, 5}, 1, 1));
-    clientEvent.setRegion(myregion);
     clientEvent.setPossibleDuplicate(true);
     clientEvent.setOperation(Operation.PUT_IF_ABSENT);
-    assertFalse(myregion.getEventTracker().hasSeenEvent(clientEvent));
+    assertThat(myRegion.getEventTracker().hasSeenEvent(clientEvent)).isFalse();
 
     System.out.println("second putIfAbsent");
-    oldValue =
-        myregion.basicBridgePutIfAbsent("mykey", valueBytes, true, null, id, true, clientEvent);
-    assertEquals(null, oldValue);
+    oldValue = myRegion.basicBridgePutIfAbsent(key, valueBytes, true, null, id, true, clientEvent);
+    assertThat(oldValue).isNull();
+  }
+
+  @Test
+  void duplicatePutIfAbsentOfNullValueDoesNotInvokeAfterUpdateListener() {
+    myRegion = (LocalRegion) cache.createRegionFactory(RegionShortcut.REPLICATE)
+        .setConcurrencyChecksEnabled(true)
+        .addCacheListener(new CacheListenerAdapter<Object, Object>() {
+          @Override
+          public void afterUpdate(EntryEvent<Object, Object> event) {
+            ++updateCount;
+          }
+        }).create("myRegion");
+
+    clientEvent.setRegion(myRegion);
+    System.out.println("first putIfAbsent of null value");
+    Object oldValue =
+        myRegion.basicBridgePutIfAbsent(key, null, true, null, id, true, clientEvent);
+    assertThat(oldValue).isNull();
+    assertThat(myRegion.containsKey(key)).isTrue();
+
+    myRegion.getEventTracker().clear();
+
+    clientEvent.setPossibleDuplicate(true);
+    clientEvent.setOperation(Operation.PUT_IF_ABSENT);
+    assertThat(myRegion.getEventTracker().hasSeenEvent(clientEvent)).isFalse();
+
+    System.out.println("second putIfAbsent of null value");

Review Comment:
   Please remove debug logging from tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org