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

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


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

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

    Fix race condition in TestThinCache (#3198)
    
    (cherry picked from commit 85f50fa83326b05da22905f17eef020b7a964ab9)
---
 .../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..405a583a084 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 (value.equals(valEntry.ref.get())) {
+            if (cause.wasEvicted()) {
+              evictions.increment();
+            }
+            return null;
+          } else {
+            // Otherwise keep the value in the map
+            return valEntry;
+          }
+        });
   }
 
   @Override

Reply via email to