Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FixedBitSetFilterCache for delete-by-query #7581

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/org/elasticsearch/index/cache/IndexCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public FilterCache filter() {
return filterCache;
}

/**
* Return the {@link FixedBitSetFilterCache} for this index.
*/
public FixedBitSetFilterCache fixedBitSetFilterCache() {
return fixedBitSetFilterCache;
}

public DocSetCache docSet() {
return this.docSetCache;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/elasticsearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -650,13 +651,13 @@ static class DeleteByQuery {
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;
Expand Down Expand Up @@ -691,7 +692,7 @@ public boolean nested() {
return parentFilter != null;
}

public Filter parentFilter() {
public FixedBitSetFilter parentFilter() {
return parentFilter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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;
Expand All @@ -39,7 +39,7 @@
*/
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
Expand All @@ -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;
Expand Down Expand Up @@ -80,9 +80,9 @@ static class IncludeNestedDocsWeight extends Weight {

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;
Expand Down Expand Up @@ -112,20 +112,11 @@ public Scorer scorer(AtomicReaderContext context, Bits acceptDocs) throws IOExce
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
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;
Expand All @@ -68,7 +70,6 @@
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;
Expand Down Expand Up @@ -465,7 +466,7 @@ public Engine.DeleteByQuery prepareDeleteByQuery(BytesReference source, @Nullabl
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);
}

Expand Down