Instantiate facets/aggregations during the QUERY phase.

In case of a DFS_QUERY_THEN_FETCH request, facets and aggregations are currently
instantiated during the DFS phase while they only become useful during the QUERY
phase. By instantiating during the QUERY phase instead, we can make better use
of recycling since objects will have a shorter life out of the recyclers.

Close #5821
This commit is contained in:
Adrien Grand 2014-04-15 19:02:45 +02:00
parent d8880f2906
commit d792d14926
2 changed files with 7 additions and 5 deletions

View File

@ -84,9 +84,7 @@ public abstract class Aggregator implements Releasable, ReaderContextAware {
assert factories != null : "sub-factories provided to BucketAggregator must not be null, use AggragatorFactories.EMPTY instead"; assert factories != null : "sub-factories provided to BucketAggregator must not be null, use AggragatorFactories.EMPTY instead";
this.factories = factories; this.factories = factories;
this.subAggregators = factories.createSubAggregators(this, estimatedBucketsCount); this.subAggregators = factories.createSubAggregators(this, estimatedBucketsCount);
// TODO: change it to SEARCH_PHASE, but this would imply allocating the aggregators in the QUERY context.searchContext().addReleasable(this, Lifetime.PHASE);
// phase instead of DFS like it is done today
context.searchContext().addReleasable(this, Lifetime.CONTEXT);
} }
/** /**

View File

@ -89,11 +89,15 @@ public class QueryPhase implements SearchPhase {
@Override @Override
public void preProcess(SearchContext context) { public void preProcess(SearchContext context) {
context.preProcess(); context.preProcess();
facetPhase.preProcess(context);
aggregationPhase.preProcess(context);
} }
public void execute(SearchContext searchContext) throws QueryPhaseExecutionException { public void execute(SearchContext searchContext) throws QueryPhaseExecutionException {
// Pre-process facets and aggregations as late as possible. In the case of a DFS_Q_T_F
// request, preProcess is called on the DFS phase phase, this is why we pre-process them
// here to make sure it happens during the QUERY phase
facetPhase.preProcess(searchContext);
aggregationPhase.preProcess(searchContext);
searchContext.queryResult().searchTimedOut(false); searchContext.queryResult().searchTimedOut(false);
searchContext.searcher().inStage(ContextIndexSearcher.Stage.MAIN_QUERY); searchContext.searcher().inStage(ContextIndexSearcher.Stage.MAIN_QUERY);