mirror of https://github.com/apache/lucene.git
LUCENE-6918: LRUQueryCache.onDocIdSetEviction is only called when at least one DocIdSet is being evicted. (Adrien Grand)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1717947 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4a4f2a00e7
commit
f9b446d66f
|
@ -119,6 +119,11 @@ Optimizations
|
|||
particular to rewrite queries that look like: "+*:* #filter" to a
|
||||
"ConstantScore(filter)". (Adrien Grand)
|
||||
|
||||
Bug Fixes
|
||||
|
||||
* LUCENE-6918: LRUQueryCache.onDocIdSetEviction is only called when at least
|
||||
one DocIdSet is being evicted. (Adrien Grand)
|
||||
|
||||
======================= Lucene 5.4.0 =======================
|
||||
|
||||
New Features
|
||||
|
|
|
@ -297,7 +297,13 @@ public class LRUQueryCache implements QueryCache, Accountable {
|
|||
final LeafCache leafCache = cache.remove(coreKey);
|
||||
if (leafCache != null) {
|
||||
ramBytesUsed -= HASHTABLE_RAM_BYTES_PER_ENTRY;
|
||||
onDocIdSetEviction(coreKey, leafCache.cache.size(), leafCache.ramBytesUsed);
|
||||
final int numEntries = leafCache.cache.size();
|
||||
if (numEntries > 0) {
|
||||
onDocIdSetEviction(coreKey, numEntries, leafCache.ramBytesUsed);
|
||||
} else {
|
||||
assert numEntries == 0;
|
||||
assert leafCache.ramBytesUsed == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1165,4 +1165,31 @@ public class TestLRUQueryCache extends LuceneTestCase {
|
|||
searcher.getIndexReader().close();
|
||||
dir.close();
|
||||
}
|
||||
|
||||
public void testEvictEmptySegmentCache() throws IOException {
|
||||
Directory dir = newDirectory();
|
||||
final RandomIndexWriter w = new RandomIndexWriter(random(), dir);
|
||||
w.addDocument(new Document());
|
||||
final DirectoryReader reader = w.getReader();
|
||||
final IndexSearcher searcher = newSearcher(reader);
|
||||
final LRUQueryCache queryCache = new LRUQueryCache(2, 100000) {
|
||||
@Override
|
||||
protected void onDocIdSetEviction(Object readerCoreKey, int numEntries, long sumRamBytesUsed) {
|
||||
super.onDocIdSetEviction(readerCoreKey, numEntries, sumRamBytesUsed);
|
||||
assertTrue(numEntries > 0);
|
||||
}
|
||||
};
|
||||
|
||||
searcher.setQueryCache(queryCache);
|
||||
searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
|
||||
|
||||
Query query = new DummyQuery();
|
||||
searcher.count(query);
|
||||
assertEquals(Collections.singletonList(query), queryCache.cachedQueries());
|
||||
queryCache.clearQuery(query);
|
||||
|
||||
reader.close(); // make sure this does not trigger eviction of segment caches with no entries
|
||||
w.close();
|
||||
dir.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue