iprithv commented on code in PR #16212:
URL: https://github.com/apache/lucene/pull/16212#discussion_r3378503969
##########
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:
cleanUp() runs at most once per minute (or manually). lock is per-partition,
not global.. with 16 partitions we only block 1/16th of the cache at a time.
this is also the same pattern evictIfNecessary() already uses, it holds the
write lock while iterating and removing entries. old code iterated
HashMap.keySet() with no lock at all, which is what caused the
ConcurrentModificationException.
--
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]