Skip to content

Commit

Permalink
add explicit filter clears on reader finished
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed May 21, 2011
1 parent d2cdcb1 commit 9c9cec8
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*
* @author kimchy (shay.banon)
*/
public abstract class AbstractConcurrentMapFilterCache extends AbstractIndexComponent implements FilterCache {
public abstract class AbstractConcurrentMapFilterCache extends AbstractIndexComponent implements FilterCache, IndexReader.ReaderFinishedListener {

final ConcurrentMap<Object, ReaderValue> cache;

Expand Down Expand Up @@ -97,6 +97,14 @@ protected ConcurrentMap<Filter, DocSet> buildFilterMap() {
cache.clear();
}

@Override public void finished(IndexReader reader) {
ReaderValue readerValue = cache.remove(reader.getCoreCacheKey());
// help soft/weak handling GC
if (readerValue != null) {
readerValue.filters().clear();
}
}

@Override public void clear(IndexReader reader) {
ReaderValue readerValue = cache.remove(reader.getCoreCacheKey());
// help soft/weak handling GC
Expand Down Expand Up @@ -156,6 +164,8 @@ static class FilterCacheFilterWrapper extends Filter {
ReaderValue prev = cache.cache.putIfAbsent(reader.getCoreCacheKey(), readerValue);
if (prev != null) {
readerValue = prev;
} else {
reader.addReaderFinishedListener(cache);
}
}
DocSet docSet = readerValue.filters().get(filter);
Expand Down

0 comments on commit 9c9cec8

Please sign in to comment.