iprithv commented on code in PR #16212:
URL: https://github.com/apache/lucene/pull/16212#discussion_r3383124919


##########
lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java:
##########
@@ -1059,6 +1059,35 @@ void remove(QueryCacheKey queryCacheKey) {
       remove(queryCacheKey, -1);
     }
 
+    /**
+     * Remove all cache entries whose segment cache key is in {@code 
keysToRemove} or whose query is
+     * in {@code queriesToRemove}. Runs under the partition write lock so that 
iteration of the
+     * underlying {@code HashMap} does not race with concurrent mutation.
+     *
+     * <p>Note: {@link #remove(QueryCacheKey, long)} re-acquires the write 
lock, which is safe
+     * because {@link 
java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock} is reentrant.
+     * This matches the pattern used by {@link #evictIfNecessary()}.
+     */
+    void removeMatching(Set<IndexReader.CacheKey> keysToRemove, Set<Query> 
queriesToRemove) {
+      writeLock.lock();

Review Comment:
   evictIfNecessary() exits early, but the key pattern is the same, hold the 
write lock for the duration of the iteration. removeMatching() scans at most 
maxSize/16 entries per partition, once per minute. that's not expensive. 
snapshot alternative would need a read lock (which also blocks writers), 
allocate a full copy, then acquire/release the write lock per removal. more 
work, not less.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to