sgup432 commented on code in PR #16212:
URL: https://github.com/apache/lucene/pull/16212#discussion_r3462455838
##########
lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java:
##########
@@ -1059,6 +1064,36 @@ 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}. The scan phase runs under a read lock so
that concurrent readers
+ * are not blocked; the write lock is acquired only for the brief removal
phase.
+ */
+ void removeMatching(Set<IndexReader.CacheKey> keysToRemove, Set<Query>
queriesToRemove) {
+ List<QueryCacheKey> toRemove = new ArrayList<>();
+ readLock.lock();
Review Comment:
We don't need a read lock now
##########
lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java:
##########
@@ -1059,6 +1064,36 @@ 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}. The scan phase runs under a read lock so
that concurrent readers
+ * are not blocked; the write lock is acquired only for the brief removal
phase.
+ */
+ void removeMatching(Set<IndexReader.CacheKey> keysToRemove, Set<Query>
queriesToRemove) {
+ List<QueryCacheKey> toRemove = new ArrayList<>();
+ readLock.lock();
+ try {
+ for (QueryCacheKey queryCacheKey : cache.keySet()) {
Review Comment:
We need to use `keys()` here instead of `cache.keySet()`
##########
lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java:
##########
@@ -1290,14 +1325,8 @@ public synchronized void cleanUp() {
keysToClean.removeAll(keysToCleanCopy);
queriesToClean.removeAll(queriesToCleanCopy);
- for (QueryCacheKey queryCacheKey : keys()) {
- boolean shouldEvict =
- (queryCacheKey.cacheKey != null &&
keysToCleanCopy.contains(queryCacheKey.cacheKey))
- || (queryCacheKey.query != null &&
queriesToCleanCopy.contains(queryCacheKey.query));
- if (shouldEvict) {
- int partitionNumber = getPartitionNumber(queryCacheKey);
- lruQueryCachePartition[partitionNumber].remove(queryCacheKey);
- }
+ for (int i = 0; i < numberOfPartitions; i++) {
+ lruQueryCachePartition[i].removeMatching(keysToCleanCopy,
queriesToCleanCopy);
Review Comment:
We don't need this logic. We can infer partition number from the cache key,
so checking for each partition is unnecessary.
We can keep the original logic now considering
`lruQueryCachePartition.keys()` is now returning copies instead of original
keys. You can verify by running your unit test below.
--
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]