Core: Use FixedBitSetFilterCache for delete-by-query.

Leftover from #7037.
Close #7581
This commit is contained in:
Adrien Grand 2014-09-04 02:44:03 +02:00
parent 144af9c910
commit 8bafb5fc8e
4 changed files with 20 additions and 20 deletions

View File

@ -65,6 +65,13 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo
return filterCache;
}
/**
* Return the {@link FixedBitSetFilterCache} for this index.
*/
public FixedBitSetFilterCache fixedBitSetFilterCache() {
return fixedBitSetFilterCache;
}
public QueryParserCache queryParserCache() {
return this.queryParserCache;
}

View File

@ -34,6 +34,7 @@ import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.cache.fixedbitset.FixedBitSetFilter;
import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.ParseContext.Document;
@ -650,13 +651,13 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
private final String[] filteringAliases;
private final Filter aliasFilter;
private final String[] types;
private final Filter parentFilter;
private final FixedBitSetFilter parentFilter;
private final Operation.Origin origin;
private final long startTime;
private long endTime;
public DeleteByQuery(Query query, BytesReference source, @Nullable String[] filteringAliases, @Nullable Filter aliasFilter, Filter parentFilter, Operation.Origin origin, long startTime, String... types) {
public DeleteByQuery(Query query, BytesReference source, @Nullable String[] filteringAliases, @Nullable Filter aliasFilter, FixedBitSetFilter parentFilter, Operation.Origin origin, long startTime, String... types) {
this.query = query;
this.source = source;
this.types = types;
@ -691,7 +692,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
return parentFilter != null;
}
public Filter parentFilter() {
public FixedBitSetFilter parentFilter() {
return parentFilter;
}

View File

@ -25,7 +25,7 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.common.lucene.docset.DocIdSets;
import org.elasticsearch.index.cache.fixedbitset.FixedBitSetFilter;
import java.io.IOException;
import java.util.Collection;
@ -39,7 +39,7 @@ import java.util.Set;
*/
public class IncludeNestedDocsQuery extends Query {
private final Filter parentFilter;
private final FixedBitSetFilter parentFilter;
private final Query parentQuery;
// If we are rewritten, this is the original childQuery we
@ -50,7 +50,7 @@ public class IncludeNestedDocsQuery extends Query {
private final Query origParentQuery;
public IncludeNestedDocsQuery(Query parentQuery, Filter parentFilter) {
public IncludeNestedDocsQuery(Query parentQuery, FixedBitSetFilter parentFilter) {
this.origParentQuery = parentQuery;
this.parentQuery = parentQuery;
this.parentFilter = parentFilter;
@ -80,9 +80,9 @@ public class IncludeNestedDocsQuery extends Query {
private final Query parentQuery;
private final Weight parentWeight;
private final Filter parentsFilter;
private final FixedBitSetFilter parentsFilter;
IncludeNestedDocsWeight(Query parentQuery, Weight parentWeight, Filter parentsFilter) {
IncludeNestedDocsWeight(Query parentQuery, Weight parentWeight, FixedBitSetFilter parentsFilter) {
this.parentQuery = parentQuery;
this.parentWeight = parentWeight;
this.parentsFilter = parentsFilter;
@ -112,20 +112,11 @@ public class IncludeNestedDocsQuery extends Query {
return null;
}
DocIdSet parents = parentsFilter.getDocIdSet(context, acceptDocs);
FixedBitSet parents = parentsFilter.getDocIdSet(context, acceptDocs);
if (parents == null) {
// No matches
return null;
}
if (!(parents instanceof FixedBitSet)) {
if (parents.isCacheable()) {
// the filter is cached, yet not with the right type
throw new IllegalStateException("parentFilter must return FixedBitSet; got " + parents);
} else {
// may happen if the filter cache type is none
parents = DocIdSets.toFixedBitSet(parents.iterator(), context.reader().maxDoc());
}
}
int firstParentDoc = parentScorer.nextDoc();
if (firstParentDoc == DocIdSetIterator.NO_MORE_DOCS) {

View File

@ -48,6 +48,8 @@ import org.elasticsearch.index.aliases.IndexAliasesService;
import org.elasticsearch.index.cache.IndexCache;
import org.elasticsearch.index.cache.filter.FilterCacheStats;
import org.elasticsearch.index.cache.filter.ShardFilterCache;
import org.elasticsearch.index.cache.fixedbitset.FixedBitSetFilter;
import org.elasticsearch.index.cache.fixedbitset.ShardFixedBitSetFilterCache;
import org.elasticsearch.index.cache.id.IdCacheStats;
import org.elasticsearch.index.cache.query.ShardQueryCache;
import org.elasticsearch.index.codec.CodecService;
@ -68,7 +70,6 @@ import org.elasticsearch.index.merge.scheduler.MergeSchedulerProvider;
import org.elasticsearch.index.percolator.PercolatorQueriesRegistry;
import org.elasticsearch.index.percolator.stats.ShardPercolateService;
import org.elasticsearch.index.query.IndexQueryParserService;
import org.elasticsearch.index.cache.fixedbitset.ShardFixedBitSetFilterCache;
import org.elasticsearch.index.refresh.RefreshStats;
import org.elasticsearch.index.search.nested.NonNestedDocsFilter;
import org.elasticsearch.index.search.stats.SearchStats;
@ -465,7 +466,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
query = filterQueryIfNeeded(query, types);
Filter aliasFilter = indexAliasesService.aliasFilter(filteringAliases);
Filter parentFilter = mapperService.hasNested() ? indexCache.filter().cache(NonNestedDocsFilter.INSTANCE) : null;
FixedBitSetFilter parentFilter = mapperService.hasNested() ? indexCache.fixedBitSetFilterCache().getFixedBitSetFilter(NonNestedDocsFilter.INSTANCE) : null;
return new Engine.DeleteByQuery(query, source, filteringAliases, aliasFilter, parentFilter, origin, startTime, types);
}