Skip to content

Commit bb5b8eb

Browse files
committed
Fork LRUQueryCache
1 parent 27fabf4 commit bb5b8eb

File tree

2 files changed

+941
-3
lines changed

2 files changed

+941
-3
lines changed

server/src/main/java/org/elasticsearch/indices/IndicesQueryCache.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
14+
import org.apache.lucene.index.IndexReader;
1415
import org.apache.lucene.index.LeafReaderContext;
1516
import org.apache.lucene.search.Explanation;
16-
import org.apache.lucene.search.LRUQueryCache;
1717
import org.apache.lucene.search.Query;
1818
import org.apache.lucene.search.QueryCache;
1919
import org.apache.lucene.search.QueryCachingPolicy;
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.index.cache.query.QueryCacheStats;
3131
import org.elasticsearch.index.shard.IndexShard;
3232
import org.elasticsearch.index.shard.ShardId;
33+
import org.elasticsearch.lucene.search.XLRUQueryCache;
3334

3435
import java.io.Closeable;
3536
import java.io.IOException;
@@ -66,7 +67,7 @@ public class IndicesQueryCache implements QueryCache, Closeable {
6667
Property.NodeScope
6768
);
6869

69-
private final LRUQueryCache cache;
70+
private final XLRUQueryCache cache;
7071
private final ShardCoreKeyMap shardKeyMap = new ShardCoreKeyMap();
7172
private final Map<ShardId, Stats> shardStats = new ConcurrentHashMap<>();
7273
private volatile long sharedRamBytesUsed;
@@ -336,7 +337,7 @@ public void onClose(ShardId shardId) {
336337
shardStats.remove(shardId);
337338
}
338339

339-
private class ElasticsearchLRUQueryCache extends LRUQueryCache {
340+
private class ElasticsearchLRUQueryCache extends XLRUQueryCache {
340341

341342
ElasticsearchLRUQueryCache(int maxSize, long maxRamBytesUsed, Predicate<LeafReaderContext> leavesToCache, float skipFactor) {
342343
super(maxSize, maxRamBytesUsed, leavesToCache, skipFactor);
@@ -432,5 +433,16 @@ protected void onMiss(Object readerCoreKey, Query filter) {
432433
final Stats shardStats = getOrCreateStats(readerCoreKey);
433434
shardStats.missCount += 1;
434435
}
436+
437+
@Override
438+
protected CacheAndCount tryPopulateCache(
439+
IndexReader.CacheHelper cacheKey,
440+
Weight weight,
441+
ScorerSupplier scorerSupplier,
442+
LeafReaderContext context
443+
) throws IOException {
444+
// TODO: handle intra-segment Weight
445+
return super.tryPopulateCache(cacheKey, weight, scorerSupplier, context);
446+
}
435447
}
436448
}

0 commit comments

Comments
 (0)