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


##########
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:
   We shouldn't do this. As by doing this, we are essentially taking a global 
lock per partition, and then iterating over all the partition cache keys, and 
most of the time you may end up clearing nothing or only few. Instead we should 
only take write lock when required ie when we need to remove a certain key. 
   
   As mentioned below, lets return a point in time snapshot key set, and work 
with that? 



##########
lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java:
##########
@@ -1290,14 +1319,8 @@ public synchronized void cleanUp() {
     keysToClean.removeAll(keysToCleanCopy);
     queriesToClean.removeAll(queriesToCleanCopy);
 
-    for (QueryCacheKey queryCacheKey : keys()) {

Review Comment:
   Why not just return a snapshot/copy of cache keys here instead? That way we 
won't run into Concurrent modification exception. Also the approach taken as 
part of this PR will regress the performance due to conservative locking.



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