You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by nk...@apache.org on 2016/02/08 23:35:59 UTC
[24/50] [abbrv] lucene-solr git commit: LUCENE-6918:
LRUQueryCache.onDocIdSetEviction is only called when at least one DocIdSet is
being evicted.
LUCENE-6918: LRUQueryCache.onDocIdSetEviction is only called when at least one DocIdSet is being evicted.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene_solr_5_4@1724044 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/21ccf61a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/21ccf61a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/21ccf61a
Branch: refs/heads/branch_5_4
Commit: 21ccf61a263606cc323d26467c3075630a944c58
Parents: 83df694
Author: Adrien Grand <jp...@apache.org>
Authored: Mon Jan 11 14:46:33 2016 +0000
Committer: Adrien Grand <jp...@apache.org>
Committed: Mon Jan 11 14:46:33 2016 +0000
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 ++
.../org/apache/lucene/search/LRUQueryCache.java | 8 ++++-
.../apache/lucene/search/TestLRUQueryCache.java | 34 +++++++++++++++++---
3 files changed, 39 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/21ccf61a/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index ddadd45..a0bf877 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -8,6 +8,9 @@ http://s.apache.org/luceneversions
Bug Fixes
+* LUCENE-6918: LRUQueryCache.onDocIdSetEviction is only called when at least
+ one DocIdSet is being evicted. (Adrien Grand)
+
* LUCENE-6946: SortField.equals now takes the missingValue parameter into
account. (Adrien Grand)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/21ccf61a/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java b/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
index 9ff0c40..cf79c9d 100644
--- a/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
+++ b/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java
@@ -300,7 +300,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;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/21ccf61a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
index 796ac4c..2488521 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
@@ -359,15 +359,12 @@ public class TestLRUQueryCache extends LuceneTestCase {
@Override
public boolean equals(Object obj) {
- if (obj instanceof DummyQuery == false) {
- return false;
- }
- return id == ((DummyQuery) obj).id;
+ return super.equals(obj) && id == ((DummyQuery) obj).id;
}
@Override
public int hashCode() {
- return id;
+ return 31 * super.hashCode() + id;
}
@Override
@@ -1173,4 +1170,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();
+ }
}