allow to clear by reader the new field data cache
This commit is contained in:
parent
c67386f644
commit
6b92b592b4
|
@ -1,5 +1,6 @@
|
|||
package org.elasticsearch.index.fielddata;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.AbstractIndexComponent;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
@ -30,4 +31,9 @@ public abstract class AbstractIndexFieldData<FD extends AtomicFieldData> extends
|
|||
public void clear() {
|
||||
cache.clear(index, fieldNames.indexName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(IndexReader reader) {
|
||||
cache.clear(index, reader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.fielddata;
|
||||
|
||||
import org.apache.lucene.index.AtomicReaderContext;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.search.FieldComparatorSource;
|
||||
import org.apache.lucene.search.SortField;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -63,6 +64,8 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
|
|||
*/
|
||||
void clear();
|
||||
|
||||
void clear(IndexReader reader);
|
||||
|
||||
// we need this extended source we we have custom comparators to reuse our field data
|
||||
// in this case, we need to reduce type that will be used when search results are reduced
|
||||
// on another node (we don't have the custom source them...)
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.index.fielddata;
|
|||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import org.apache.lucene.index.AtomicReaderContext;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.SegmentReader;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
||||
|
@ -38,6 +39,8 @@ public interface IndexFieldDataCache {
|
|||
|
||||
void clear(Index index, String fieldName);
|
||||
|
||||
void clear(Index index, IndexReader reader);
|
||||
|
||||
/**
|
||||
* The resident field data cache is a *per field* cache that keeps all the values in memory.
|
||||
*/
|
||||
|
@ -76,6 +79,11 @@ public interface IndexFieldDataCache {
|
|||
public void clear(Index index, String fieldName) {
|
||||
cache.invalidateAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(Index index, IndexReader reader) {
|
||||
cache.invalidate(reader.getCoreCacheKey());
|
||||
}
|
||||
}
|
||||
|
||||
static class Resident extends FieldBased {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.fielddata;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
|
@ -96,6 +97,12 @@ public class IndexFieldDataService extends AbstractIndexComponent {
|
|||
}
|
||||
}
|
||||
|
||||
public void clear(IndexReader reader) {
|
||||
for (IndexFieldData indexFieldData : loadedFieldData.values()) {
|
||||
indexFieldData.clear(reader);
|
||||
}
|
||||
}
|
||||
|
||||
public FieldDataStats stats() {
|
||||
// TODO: compute the memory size here...
|
||||
return new FieldDataStats();
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.elasticsearch.index.engine.Engine;
|
|||
import org.elasticsearch.index.fielddata.BytesValues;
|
||||
import org.elasticsearch.index.fielddata.FieldDataType;
|
||||
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
|
||||
import org.elasticsearch.index.query.IndexQueryParserService;
|
||||
|
@ -153,6 +154,7 @@ public class PercolatorExecutor extends AbstractIndexComponent {
|
|||
private final IndexQueryParserService queryParserService;
|
||||
|
||||
private final IndexCache indexCache;
|
||||
private final IndexFieldDataService fieldDataService;
|
||||
|
||||
private final Map<String, Query> queries = ConcurrentCollections.newConcurrentMap();
|
||||
|
||||
|
@ -162,11 +164,12 @@ public class PercolatorExecutor extends AbstractIndexComponent {
|
|||
@Inject
|
||||
public PercolatorExecutor(Index index, @IndexSettings Settings indexSettings,
|
||||
MapperService mapperService, IndexQueryParserService queryParserService,
|
||||
IndexCache indexCache) {
|
||||
IndexCache indexCache, IndexFieldDataService fieldDataService) {
|
||||
super(index, indexSettings);
|
||||
this.mapperService = mapperService;
|
||||
this.queryParserService = queryParserService;
|
||||
this.indexCache = indexCache;
|
||||
this.fieldDataService = fieldDataService;
|
||||
}
|
||||
|
||||
public void setIndicesService(IndicesService indicesService) {
|
||||
|
@ -347,6 +350,7 @@ public class PercolatorExecutor extends AbstractIndexComponent {
|
|||
} finally {
|
||||
// explicitly clear the reader, since we can only register on callback on SegmentReader
|
||||
indexCache.clear(searcher.getIndexReader());
|
||||
fieldDataService.clear(searcher.getIndexReader());
|
||||
}
|
||||
|
||||
return new Response(matches, request.doc().mappingsModified());
|
||||
|
|
Loading…
Reference in New Issue