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

houston pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 85f50fa8332 Fix race condition in TestThinCache (#3198)
85f50fa8332 is described below

commit 85f50fa83326b05da22905f17eef020b7a964ab9
Author: Houston Putman <[email protected]>
AuthorDate: Fri Feb 21 09:58:45 2025 -0600

    Fix race condition in TestThinCache (#3198)
---
 .../src/test/org/apache/solr/search/ThinCache.java | 23 ++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/solr/core/src/test/org/apache/solr/search/ThinCache.java 
b/solr/core/src/test/org/apache/solr/search/ThinCache.java
index 75910b94bb9..ea7a155922e 100644
--- a/solr/core/src/test/org/apache/solr/search/ThinCache.java
+++ b/solr/core/src/test/org/apache/solr/search/ThinCache.java
@@ -345,10 +345,25 @@ public class ThinCache<S, K, V> extends SolrCacheBase
 
   @Override
   public void onRemoval(K key, V value, RemovalCause cause) {
-    if (cause.wasEvicted()) {
-      evictions.increment();
-    }
-    local.remove(key);
+    // Only remove if the current value is the same as the removal.
+    // RemovalListener gives us no guarantee that onRemoval() will be called
+    // before the same key gets updated again.
+    // We are still not protecting against a removal then a put() with the
+    // same value in quick succession.
+    local.computeIfPresent(
+        key,
+        (keyEntry, valEntry) -> {
+          // Delete only if the value being deleted is the same as what we 
have locally
+          if (valEntry.ref.refersTo(value)) {
+            if (cause.wasEvicted()) {
+              evictions.increment();
+            }
+            return null;
+          } else {
+            // Otherwise keep the value in the map
+            return valEntry;
+          }
+        });
   }
 
   @Override

Reply via email to