anton-vinogradov commented on code in PR #13316:
URL: https://github.com/apache/ignite/pull/13316#discussion_r3579103423


##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/IgniteCacheAtomicProtocolTest.java:
##########
@@ -864,6 +868,114 @@ private void readerUpdateDhtFails(boolean 
updateNearEnabled,
         checkData(map);
     }
 
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testNearEntryUpdateRacePut() throws Exception {
+        nearEntryUpdateRace(cache -> cache.put(0, 1), F.asMap(0, 2));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testNearEntryUpdateRacePutIfAbsent() throws Exception {
+        nearEntryUpdateRace(cache -> assertTrue(cache.putIfAbsent(0, 1)), 
F.asMap(0, 2));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testNearEntryUpdateRaceInvoke() throws Exception {
+        nearEntryUpdateRace(cache -> cache.invoke(0, new 
SetValueEntryProcessor(1)), F.asMap(0, 2));
+    }

Review Comment:
   Added PRIMARY_SYNC — the race tests now run for both FULL_SYNC and 
PRIMARY_SYNC.
   
   FULL_ASYNC is intentionally left out: in that mode the primary does not send 
`GridNearAtomicUpdateResponse` to the near node at all (`GridDhtAtomicCache`: 
`if (req.writeSynchronizationMode() != FULL_ASYNC)`), so there is no 
near-update response that could be reordered against the reader update — the 
race this test reproduces cannot occur, and the harness (which blocks that 
response to hold the in-flight window open) would have nothing to block. The 
reservation itself is taken at `map()` time regardless of the write 
synchronization mode, so the fix is not mode-specific.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java:
##########
@@ -153,6 +157,9 @@ public abstract class GridNearAtomicAbstractUpdateFuture 
extends GridCacheFuture
     /** Handle binary in interceptor operation flag. */
     protected boolean keepBinaryInInterceptor;
 
+    /** Near entries reserved against eviction for the time of update. */
+    protected Map<KeyCacheObject, GridNearCacheEntry> reservedEntries;

Review Comment:
   Done, made it `private`.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java:
##########
@@ -153,6 +157,9 @@ public abstract class GridNearAtomicAbstractUpdateFuture 
extends GridCacheFuture
     /** Handle binary in interceptor operation flag. */
     protected boolean keepBinaryInInterceptor;
 
+    /** Near entries reserved against eviction for the time of update. */
+    protected Map<KeyCacheObject, GridNearCacheEntry> reservedEntries;

Review Comment:
   The reservation is needed regardless of a configured eviction policy. The 
empty near entry created for the in-flight window is removed via 
`markObsoleteIfEmpty` inside `GridCacheEvictionManager.touch()`, which runs 
before the `if (!plcEnabled) return;` check — i.e. independent of any eviction 
policy. `reserveEviction()` sets `evictionDisabled()`, and `markObsolete0()` 
early-returns `false` while it is set, which is exactly what keeps the 
placeholder alive for the whole operation.
   
   Empirically, the `testNearEntryUpdateRace*` tests use a plain 
`NearCacheConfiguration` with no eviction policy and reproduce the bug on 
master / pass with the fix. The configured-eviction case is covered separately 
by `testNearEvictionPolicyOnUpdates`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to