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

nnag pushed a commit to branch support/1.15
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/support/1.15 by this push:
     new 1613857913 GEODE-10294: Compare invalid token during putIfAbsent 
retry. (#7679)
1613857913 is described below

commit 1613857913ec3a10cfa1cdd816ff2f28f9fde3e1
Author: Eric Shu <[email protected]>
AuthorDate: Fri May 13 16:21:47 2022 -0700

    GEODE-10294: Compare invalid token during putIfAbsent retry. (#7679)
    
     * During putIfAbsent retry, comparing invalid token value when
       putIfAbsent of a null value instead.
    
    (cherry picked from commit 4f4af2a303142729708a951cc8a93f562c3de8bc)
---
 .../apache/geode/internal/cache/map/RegionMapPut.java   | 14 +++++++++++---
 .../geode/internal/cache/map/RegionMapPutTest.java      | 17 ++++++++++++++---
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/cache/map/RegionMapPut.java
 
b/geode-core/src/main/java/org/apache/geode/internal/cache/map/RegionMapPut.java
index e0b62a5976..8ff9db123b 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/cache/map/RegionMapPut.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/cache/map/RegionMapPut.java
@@ -409,9 +409,7 @@ public class RegionMapPut extends AbstractRegionMapPut {
             event.isPossibleDuplicate()) {
           Object retainedValue = getRegionEntry().getValueRetain(getOwner());
           try {
-            if (ValueComparisonHelper.checkEquals(retainedValue,
-                getEvent().getRawNewValue(),
-                isCompressedOffHeap(event), getOwner().getCache())) {
+            if (isSameValueAlreadyInCacheForPutIfAbsent(retainedValue)) {
               if (logger.isDebugEnabled()) {
                 logger.debug("retried putIfAbsent found same value already in 
cache "
                     + "- allowing the operation.  entry={}; event={}", 
getRegionEntry(),
@@ -430,6 +428,16 @@ public class RegionMapPut extends AbstractRegionMapPut {
     return true;
   }
 
+  private boolean isSameValueAlreadyInCacheForPutIfAbsent(Object 
retainedValue) {
+    if (Token.isInvalid(retainedValue)) {
+      return getEvent().getRawNewValue() == null || 
Token.isInvalid(getEvent().getRawNewValue());
+    }
+
+    return ValueComparisonHelper.checkEquals(retainedValue,
+        getEvent().getRawNewValue(),
+        isCompressedOffHeap(getEvent()), getOwner().getCache());
+  }
+
 
   private boolean isCompressedOffHeap(EntryEventImpl event) {
     return event.getRegion().getAttributes().getOffHeap()
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/map/RegionMapPutTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/map/RegionMapPutTest.java
index 7fceaeb43a..8b3d77e062 100644
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/map/RegionMapPutTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/map/RegionMapPutTest.java
@@ -137,7 +137,7 @@ public class RegionMapPutTest {
   public void doesNotSetEventOldValueIfRetriedPutIfAbsentOperation() {
     final byte[] bytes = new byte[] {1, 2, 3, 4, 5};
     givenExistingRegionEntry();
-    when(existingRegionEntry.getValue()).thenReturn(bytes);
+    when(existingRegionEntry.getValueRetain(internalRegion)).thenReturn(bytes);
     when(internalRegion.getConcurrencyChecksEnabled()).thenReturn(true);
     givenPutIfAbsentOperation(bytes); // duplicate operation
     doPut();
@@ -145,11 +145,22 @@ public class RegionMapPutTest {
     assertThat(instance.isOverwritePutIfAbsent()).isTrue();
   }
 
+  @Test
+  public void doesNotSetEventOldValueIfRetriedPutIfAbsentOperationOfNull() {
+    givenExistingRegionEntry();
+    
when(existingRegionEntry.getValueRetain(internalRegion)).thenReturn(Token.INVALID);
+    when(internalRegion.getConcurrencyChecksEnabled()).thenReturn(true);
+    givenPutIfAbsentOperation(null); // duplicate operation
+    doPut();
+    verify(event).setOldValue(null, true);
+    assertThat(instance.isOverwritePutIfAbsent()).isTrue();
+  }
+
   @Test
   public void 
overWritePutIfAbsentIsTrueIfRetriedPutIfAbsentOperationHavingValidVersionTag() {
     final byte[] bytes = new byte[] {1, 2, 3, 4, 5};
     givenExistingRegionEntry();
-    when(existingRegionEntry.getValue()).thenReturn(bytes);
+    when(existingRegionEntry.getValueRetain(internalRegion)).thenReturn(bytes);
     when(internalRegion.getConcurrencyChecksEnabled()).thenReturn(true);
     givenPutIfAbsentOperation(bytes); // duplicate operation
     when(event.hasValidVersionTag()).thenReturn(true);
@@ -162,7 +173,7 @@ public class RegionMapPutTest {
 
   private void givenPutIfAbsentOperation(byte[] bytes) {
     when(event.isPossibleDuplicate()).thenReturn(true);
-    when(event.basicGetNewValue()).thenReturn(bytes);
+    when(event.getRawNewValue()).thenReturn(bytes);
     when(event.getOperation()).thenReturn(Operation.PUT_IF_ABSENT);
     when(event.hasValidVersionTag()).thenReturn(false);
     ifNew = true;

Reply via email to