allow to clear by reader the new field data cache

This commit is contained in:
Shay Banon 2013-01-22 15:30:05 +01:00
parent c67386f644
commit 6b92b592b4
5 changed files with 29 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package org.elasticsearch.index.fielddata; package org.elasticsearch.index.fielddata;
import org.apache.lucene.index.IndexReader;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
@ -30,4 +31,9 @@ public abstract class AbstractIndexFieldData<FD extends AtomicFieldData> extends
public void clear() { public void clear() {
cache.clear(index, fieldNames.indexName()); cache.clear(index, fieldNames.indexName());
} }
@Override
public void clear(IndexReader reader) {
cache.clear(index, reader);
}
} }

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.fielddata; package org.elasticsearch.index.fielddata;
import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldComparatorSource; import org.apache.lucene.search.FieldComparatorSource;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
@ -63,6 +64,8 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
*/ */
void clear(); void clear();
void clear(IndexReader reader);
// we need this extended source we we have custom comparators to reuse our field data // 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 // 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...) // on another node (we don't have the custom source them...)

View File

@ -22,6 +22,7 @@ package org.elasticsearch.index.fielddata;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.SegmentReader; import org.apache.lucene.index.SegmentReader;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
@ -38,6 +39,8 @@ public interface IndexFieldDataCache {
void clear(Index index, String fieldName); 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. * 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) { public void clear(Index index, String fieldName) {
cache.invalidateAll(); cache.invalidateAll();
} }
@Override
public void clear(Index index, IndexReader reader) {
cache.invalidate(reader.getCoreCacheKey());
}
} }
static class Resident extends FieldBased { static class Resident extends FieldBased {

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.fielddata; package org.elasticsearch.index.fielddata;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.apache.lucene.index.IndexReader;
import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.collect.Tuple; 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() { public FieldDataStats stats() {
// TODO: compute the memory size here... // TODO: compute the memory size here...
return new FieldDataStats(); return new FieldDataStats();

View File

@ -49,6 +49,7 @@ import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.fielddata.BytesValues; import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.mapper.internal.UidFieldMapper; import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.index.query.IndexQueryParserService;
@ -153,6 +154,7 @@ public class PercolatorExecutor extends AbstractIndexComponent {
private final IndexQueryParserService queryParserService; private final IndexQueryParserService queryParserService;
private final IndexCache indexCache; private final IndexCache indexCache;
private final IndexFieldDataService fieldDataService;
private final Map<String, Query> queries = ConcurrentCollections.newConcurrentMap(); private final Map<String, Query> queries = ConcurrentCollections.newConcurrentMap();
@ -162,11 +164,12 @@ public class PercolatorExecutor extends AbstractIndexComponent {
@Inject @Inject
public PercolatorExecutor(Index index, @IndexSettings Settings indexSettings, public PercolatorExecutor(Index index, @IndexSettings Settings indexSettings,
MapperService mapperService, IndexQueryParserService queryParserService, MapperService mapperService, IndexQueryParserService queryParserService,
IndexCache indexCache) { IndexCache indexCache, IndexFieldDataService fieldDataService) {
super(index, indexSettings); super(index, indexSettings);
this.mapperService = mapperService; this.mapperService = mapperService;
this.queryParserService = queryParserService; this.queryParserService = queryParserService;
this.indexCache = indexCache; this.indexCache = indexCache;
this.fieldDataService = fieldDataService;
} }
public void setIndicesService(IndicesService indicesService) { public void setIndicesService(IndicesService indicesService) {
@ -347,6 +350,7 @@ public class PercolatorExecutor extends AbstractIndexComponent {
} finally { } finally {
// explicitly clear the reader, since we can only register on callback on SegmentReader // explicitly clear the reader, since we can only register on callback on SegmentReader
indexCache.clear(searcher.getIndexReader()); indexCache.clear(searcher.getIndexReader());
fieldDataService.clear(searcher.getIndexReader());
} }
return new Response(matches, request.doc().mappingsModified()); return new Response(matches, request.doc().mappingsModified());