add explicit filter clears on reader finished

This commit is contained in:
kimchy 2011-05-22 01:15:23 +03:00
parent 0d334bfd03
commit 10de33c94e
1 changed files with 11 additions and 1 deletions

View File

@ -49,7 +49,7 @@ import static org.elasticsearch.common.util.concurrent.ConcurrentCollections.*;
*
* @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;
@ -97,6 +97,14 @@ public abstract class AbstractConcurrentMapFilterCache extends AbstractIndexComp
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
@ -156,6 +164,8 @@ public abstract class AbstractConcurrentMapFilterCache extends AbstractIndexComp
ReaderValue prev = cache.cache.putIfAbsent(reader.getCoreCacheKey(), readerValue);
if (prev != null) {
readerValue = prev;
} else {
reader.addReaderFinishedListener(cache);
}
}
DocSet docSet = readerValue.filters().get(filter);