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:
Adrien Grand 2015-12-04 12:22:46 +00:00
parent 4a4f2a00e7
commit f9b446d66f
3 changed files with 39 additions and 1 deletions

View File

@ -119,6 +119,11 @@ Optimizations
particular to rewrite queries that look like: "+*:* #filter" to a particular to rewrite queries that look like: "+*:* #filter" to a
"ConstantScore(filter)". (Adrien Grand) "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 ======================= ======================= Lucene 5.4.0 =======================
New Features New Features

View File

@ -297,7 +297,13 @@ public class LRUQueryCache implements QueryCache, Accountable {
final LeafCache leafCache = cache.remove(coreKey); final LeafCache leafCache = cache.remove(coreKey);
if (leafCache != null) { if (leafCache != null) {
ramBytesUsed -= HASHTABLE_RAM_BYTES_PER_ENTRY; 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;
}
} }
} }

View File

@ -1165,4 +1165,31 @@ public class TestLRUQueryCache extends LuceneTestCase {
searcher.getIndexReader().close(); searcher.getIndexReader().close();
dir.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();
}
} }