From 9f6117612cf10d2a2b6630f94b5644b51291134c Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sat, 13 Jul 2013 01:00:45 +0200 Subject: [PATCH] cache recycler now node/client level component --- .../TransportClearIndicesCacheAction.java | 9 +- .../query/TransportValidateQueryAction.java | 8 +- .../action/count/TransportCountAction.java | 8 +- .../explain/TransportExplainAction.java | 8 +- .../cache/recycler/CacheRecycler.java | 100 ++++++++++ .../cache/recycler/CacheRecyclerModule.java | 44 +++++ .../recycler}/DefaultCacheRecycler.java | 89 ++++----- .../recycler/NoneCacheRecycler.java} | 26 +-- .../client/transport/TransportClient.java | 13 +- .../elasticsearch/common/CacheRecycler.java | 185 ------------------ .../index/query/IndexQueryParserService.java | 6 +- .../index/query/QueryParseContext.java | 5 + .../index/query/TopChildrenQueryParser.java | 2 +- .../index/search/child/ChildrenQuery.java | 10 +- .../index/search/child/HasChildFilter.java | 7 +- .../index/search/child/HasParentFilter.java | 5 +- .../index/search/child/ParentQuery.java | 5 +- .../index/search/child/TopChildrenQuery.java | 18 +- .../cache/filter/IndicesFilterCache.java | 10 +- .../node/internal/InternalNode.java | 6 +- .../elasticsearch/search/SearchService.java | 8 +- .../controller/SearchPhaseController.java | 7 +- .../search/facet/InternalFacet.java | 21 +- .../CountDateHistogramFacetExecutor.java | 10 +- .../DateHistogramFacetParser.java | 6 +- .../InternalCountDateHistogramFacet.java | 114 ++++++----- .../InternalFullDateHistogramFacet.java | 23 ++- .../ValueDateHistogramFacetExecutor.java | 10 +- ...ValueScriptDateHistogramFacetExecutor.java | 10 +- .../facet/filter/InternalFilterFacet.java | 3 +- .../geodistance/InternalGeoDistanceFacet.java | 4 +- .../CountHistogramFacetExecutor.java | 8 +- .../histogram/FullHistogramFacetExecutor.java | 8 +- .../InternalCountHistogramFacet.java | 106 ++++++---- .../histogram/InternalFullHistogramFacet.java | 23 ++- .../ScriptHistogramFacetExecutor.java | 8 +- .../ValueHistogramFacetExecutor.java | 10 +- .../ValueScriptHistogramFacetExecutor.java | 8 +- .../facet/query/InternalQueryFacet.java | 3 +- .../facet/range/InternalRangeFacet.java | 3 +- .../statistical/InternalStatisticalFacet.java | 3 +- .../search/facet/terms/TermsFacetParser.java | 6 +- .../doubles/InternalDoubleTermsFacet.java | 10 +- .../doubles/TermsDoubleFacetExecutor.java | 14 +- .../terms/longs/InternalLongTermsFacet.java | 8 +- .../terms/longs/TermsLongFacetExecutor.java | 14 +- .../strings/InternalStringTermsFacet.java | 10 +- .../ScriptTermsStringFieldFacetExecutor.java | 15 +- .../TermsStringOrdinalsFacetExecutor.java | 17 +- .../InternalTermsStatsDoubleFacet.java | 10 +- .../TermsStatsDoubleFacetExecutor.java | 8 +- .../longs/InternalTermsStatsLongFacet.java | 10 +- .../longs/TermsStatsLongFacetExecutor.java | 8 +- .../InternalTermsStatsStringFacet.java | 10 +- .../TermsStatsStringFacetExecutor.java | 9 +- .../search/internal/SearchContext.java | 11 +- .../aliases/IndexAliasesServiceTests.java | 2 + .../percolator/PercolatorExecutorTests.java | 2 + .../query/SimpleIndexQueryParserTests.java | 2 + .../guice/IndexQueryParserModuleTests.java | 2 + .../plugin/IndexQueryParserPlugin2Tests.java | 2 + .../plugin/IndexQueryParserPluginTests.java | 2 + 62 files changed, 615 insertions(+), 517 deletions(-) create mode 100644 src/main/java/org/elasticsearch/cache/recycler/CacheRecycler.java create mode 100644 src/main/java/org/elasticsearch/cache/recycler/CacheRecyclerModule.java rename src/main/java/org/elasticsearch/{common => cache/recycler}/DefaultCacheRecycler.java (80%) rename src/main/java/org/elasticsearch/{common/NoCacheCacheRecycler.java => cache/recycler/NoneCacheRecycler.java} (87%) delete mode 100644 src/main/java/org/elasticsearch/common/CacheRecycler.java diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java index ef4ee1337a8..8d17e499e86 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java @@ -24,13 +24,13 @@ import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException; import org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.service.IndexService; @@ -51,13 +51,16 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio private final IndicesService indicesService; private final IndicesTermsFilterCache termsFilterCache; + private final CacheRecycler cacheRecycler; @Inject public TransportClearIndicesCacheAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, - TransportService transportService, IndicesService indicesService, IndicesTermsFilterCache termsFilterCache) { + TransportService transportService, IndicesService indicesService, IndicesTermsFilterCache termsFilterCache, + CacheRecycler cacheRecycler) { super(settings, threadPool, clusterService, transportService); this.indicesService = indicesService; this.termsFilterCache = termsFilterCache; + this.cacheRecycler = cacheRecycler; } @Override @@ -147,7 +150,7 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio if (request.recycler()) { logger.info("Clear CacheRecycler on index [{}]", service.index()); clearedAtLeastOne = true; - CacheRecycler.clear(); + cacheRecycler.clear(); } if (request.idCache()) { clearedAtLeastOne = true; diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java index 337aac847b6..bc921d5231a 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException; import org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -61,11 +62,14 @@ public class TransportValidateQueryAction extends TransportBroadcastOperationAct private final ScriptService scriptService; + private final CacheRecycler cacheRecycler; + @Inject - public TransportValidateQueryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, IndicesService indicesService, ScriptService scriptService) { + public TransportValidateQueryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, IndicesService indicesService, ScriptService scriptService, CacheRecycler cacheRecycler) { super(settings, threadPool, clusterService, transportService); this.indicesService = indicesService; this.scriptService = scriptService; + this.cacheRecycler = cacheRecycler; } @Override @@ -168,7 +172,7 @@ public class TransportValidateQueryAction extends TransportBroadcastOperationAct SearchContext.setCurrent(new SearchContext(0, new ShardSearchRequest().types(request.types()), null, indexShard.searcher(), indexService, indexShard, - scriptService)); + scriptService, cacheRecycler)); try { ParsedQuery parsedQuery = queryParserService.parse(request.querySource()); valid = true; diff --git a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java index f7e3527a3f4..ba397a984f4 100644 --- a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java +++ b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException; import org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; @@ -62,12 +63,15 @@ public class TransportCountAction extends TransportBroadcastOperationAction ExtTHashMap popHashMap(); + + public abstract void pushHashMap(ExtTHashMap map); + + public abstract THashSet popHashSet(); + + public abstract void pushHashSet(THashSet map); + + public abstract ExtTDoubleObjectHashMap popDoubleObjectMap(); + + public abstract void pushDoubleObjectMap(ExtTDoubleObjectHashMap map); + + public abstract ExtTLongObjectHashMap popLongObjectMap(); + + public abstract void pushLongObjectMap(ExtTLongObjectHashMap map); + + public abstract TLongLongHashMap popLongLongMap(); + + public abstract void pushLongLongMap(TLongLongHashMap map); + + public abstract TIntIntHashMap popIntIntMap(); + + public abstract void pushIntIntMap(TIntIntHashMap map); + + public abstract TFloatIntHashMap popFloatIntMap(); + + public abstract void pushFloatIntMap(TFloatIntHashMap map); + + public abstract TDoubleIntHashMap popDoubleIntMap(); + + public abstract void pushDoubleIntMap(TDoubleIntHashMap map); + + public abstract TByteIntHashMap popByteIntMap(); + + public abstract void pushByteIntMap(TByteIntHashMap map); + + public abstract TShortIntHashMap popShortIntMap(); + + public abstract void pushShortIntMap(TShortIntHashMap map); + + public abstract TLongIntHashMap popLongIntMap(); + + public abstract void pushLongIntMap(TLongIntHashMap map); + + public abstract TObjectIntHashMap popObjectIntMap(); + + public abstract void pushObjectIntMap(TObjectIntHashMap map); + + public abstract TIntObjectHashMap popIntObjectMap(); + + public abstract void pushIntObjectMap(TIntObjectHashMap map); + + public abstract TObjectFloatHashMap popObjectFloatMap(); + + public abstract void pushObjectFloatMap(TObjectFloatHashMap map); + + public abstract Object[] popObjectArray(int size); + + public abstract void pushObjectArray(Object[] objects); + + public abstract int[] popIntArray(int size); + + public abstract int[] popIntArray(int size, int sentinal); + + public abstract void pushIntArray(int[] ints); + + public abstract void pushIntArray(int[] ints, int sentinal); + +} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/cache/recycler/CacheRecyclerModule.java b/src/main/java/org/elasticsearch/cache/recycler/CacheRecyclerModule.java new file mode 100644 index 00000000000..54682634da2 --- /dev/null +++ b/src/main/java/org/elasticsearch/cache/recycler/CacheRecyclerModule.java @@ -0,0 +1,44 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.cache.recycler; + +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.settings.Settings; + +/** + */ +public class CacheRecyclerModule extends AbstractModule { + + private final Settings settings; + + public CacheRecyclerModule(Settings settings) { + this.settings = settings; + } + + @Override + protected void configure() { + String type = settings.get("node.cache.recycler.type", "default"); + if ("none".equalsIgnoreCase(type)) { + bind(CacheRecycler.class).to(NoneCacheRecycler.class).asEagerSingleton(); + } else { + bind(CacheRecycler.class).to(DefaultCacheRecycler.class).asEagerSingleton(); + } + } +} diff --git a/src/main/java/org/elasticsearch/common/DefaultCacheRecycler.java b/src/main/java/org/elasticsearch/cache/recycler/DefaultCacheRecycler.java similarity index 80% rename from src/main/java/org/elasticsearch/common/DefaultCacheRecycler.java rename to src/main/java/org/elasticsearch/cache/recycler/DefaultCacheRecycler.java index 92c809891a8..7f5b7df9434 100644 --- a/src/main/java/org/elasticsearch/common/DefaultCacheRecycler.java +++ b/src/main/java/org/elasticsearch/cache/recycler/DefaultCacheRecycler.java @@ -17,32 +17,21 @@ * under the License. */ -package org.elasticsearch.common; +package org.elasticsearch.cache.recycler; -import gnu.trove.map.hash.TByteIntHashMap; -import gnu.trove.map.hash.TDoubleIntHashMap; -import gnu.trove.map.hash.TFloatIntHashMap; -import gnu.trove.map.hash.TIntIntHashMap; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.map.hash.TLongIntHashMap; -import gnu.trove.map.hash.TLongLongHashMap; -import gnu.trove.map.hash.TObjectFloatHashMap; -import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.map.hash.TShortIntHashMap; +import gnu.trove.map.hash.*; import gnu.trove.set.hash.THashSet; - -import java.lang.ref.SoftReference; -import java.util.Arrays; -import java.util.Queue; - import org.elasticsearch.common.trove.ExtTDoubleObjectHashMap; import org.elasticsearch.common.trove.ExtTHashMap; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -public class DefaultCacheRecycler implements Recycler { +import java.lang.ref.SoftReference; +import java.util.Arrays; +import java.util.Queue; + +public class DefaultCacheRecycler implements CacheRecycler { - @Override public void clear() { hashMap.clear(); @@ -86,7 +75,7 @@ public class DefaultCacheRecycler implements Recycler { private final SoftWrapper> hashMap = new SoftWrapper>(); /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popHashMap() + * @see org.elasticsearch.common.CacheRecycler#popHashMap() */ @Override @SuppressWarnings("unchecked") @@ -99,7 +88,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushHashMap(org.elasticsearch.common.trove.ExtTHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushHashMap(org.elasticsearch.common.trove.ExtTHashMap) */ @Override public void pushHashMap(ExtTHashMap map) { @@ -112,7 +101,7 @@ public class DefaultCacheRecycler implements Recycler { private final SoftWrapper> hashSet = new SoftWrapper>(); /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popHashSet() + * @see org.elasticsearch.common.CacheRecycler#popHashSet() */ @Override @SuppressWarnings("unchecked") @@ -125,7 +114,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushHashSet(gnu.trove.set.hash.THashSet) + * @see org.elasticsearch.common.CacheRecycler#pushHashSet(gnu.trove.set.hash.THashSet) */ @Override public void pushHashSet(THashSet map) { @@ -138,7 +127,7 @@ public class DefaultCacheRecycler implements Recycler { private final SoftWrapper> doubleObjectHashMap = new SoftWrapper>(); /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popDoubleObjectMap() + * @see org.elasticsearch.common.CacheRecycler#popDoubleObjectMap() */ @Override @SuppressWarnings("unchecked") @@ -151,7 +140,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushDoubleObjectMap(org.elasticsearch.common.trove.ExtTDoubleObjectHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushDoubleObjectMap(org.elasticsearch.common.trove.ExtTDoubleObjectHashMap) */ @Override public void pushDoubleObjectMap(ExtTDoubleObjectHashMap map) { @@ -164,7 +153,7 @@ public class DefaultCacheRecycler implements Recycler { private final SoftWrapper> longObjectHashMap = new SoftWrapper>(); /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popLongObjectMap() + * @see org.elasticsearch.common.CacheRecycler#popLongObjectMap() */ @Override @SuppressWarnings("unchecked") @@ -177,7 +166,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushLongObjectMap(org.elasticsearch.common.trove.ExtTLongObjectHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushLongObjectMap(org.elasticsearch.common.trove.ExtTLongObjectHashMap) */ @Override public void pushLongObjectMap(ExtTLongObjectHashMap map) { @@ -190,7 +179,7 @@ public class DefaultCacheRecycler implements Recycler { private final SoftWrapper> longLongHashMap = new SoftWrapper>(); /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popLongLongMap() + * @see org.elasticsearch.common.CacheRecycler#popLongLongMap() */ @Override public TLongLongHashMap popLongLongMap() { @@ -202,7 +191,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushLongLongMap(gnu.trove.map.hash.TLongLongHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushLongLongMap(gnu.trove.map.hash.TLongLongHashMap) */ @Override public void pushLongLongMap(TLongLongHashMap map) { @@ -215,7 +204,7 @@ public class DefaultCacheRecycler implements Recycler { /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popIntIntMap() + * @see org.elasticsearch.common.CacheRecycler#popIntIntMap() */ @Override public TIntIntHashMap popIntIntMap() { @@ -227,7 +216,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushIntIntMap(gnu.trove.map.hash.TIntIntHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushIntIntMap(gnu.trove.map.hash.TIntIntHashMap) */ @Override public void pushIntIntMap(TIntIntHashMap map) { @@ -242,7 +231,7 @@ public class DefaultCacheRecycler implements Recycler { /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popFloatIntMap() + * @see org.elasticsearch.common.CacheRecycler#popFloatIntMap() */ @Override public TFloatIntHashMap popFloatIntMap() { @@ -254,7 +243,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushFloatIntMap(gnu.trove.map.hash.TFloatIntHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushFloatIntMap(gnu.trove.map.hash.TFloatIntHashMap) */ @Override public void pushFloatIntMap(TFloatIntHashMap map) { @@ -269,7 +258,7 @@ public class DefaultCacheRecycler implements Recycler { /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popDoubleIntMap() + * @see org.elasticsearch.common.CacheRecycler#popDoubleIntMap() */ @Override public TDoubleIntHashMap popDoubleIntMap() { @@ -281,7 +270,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushDoubleIntMap(gnu.trove.map.hash.TDoubleIntHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushDoubleIntMap(gnu.trove.map.hash.TDoubleIntHashMap) */ @Override public void pushDoubleIntMap(TDoubleIntHashMap map) { @@ -296,7 +285,7 @@ public class DefaultCacheRecycler implements Recycler { /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popByteIntMap() + * @see org.elasticsearch.common.CacheRecycler#popByteIntMap() */ @Override public TByteIntHashMap popByteIntMap() { @@ -308,7 +297,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushByteIntMap(gnu.trove.map.hash.TByteIntHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushByteIntMap(gnu.trove.map.hash.TByteIntHashMap) */ @Override public void pushByteIntMap(TByteIntHashMap map) { @@ -323,7 +312,7 @@ public class DefaultCacheRecycler implements Recycler { /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popShortIntMap() + * @see org.elasticsearch.common.CacheRecycler#popShortIntMap() */ @Override public TShortIntHashMap popShortIntMap() { @@ -335,7 +324,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushShortIntMap(gnu.trove.map.hash.TShortIntHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushShortIntMap(gnu.trove.map.hash.TShortIntHashMap) */ @Override public void pushShortIntMap(TShortIntHashMap map) { @@ -350,7 +339,7 @@ public class DefaultCacheRecycler implements Recycler { /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popLongIntMap() + * @see org.elasticsearch.common.CacheRecycler#popLongIntMap() */ @Override public TLongIntHashMap popLongIntMap() { @@ -366,7 +355,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushLongIntMap(gnu.trove.map.hash.TLongIntHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushLongIntMap(gnu.trove.map.hash.TLongIntHashMap) */ @Override public void pushLongIntMap(TLongIntHashMap map) { @@ -380,7 +369,7 @@ public class DefaultCacheRecycler implements Recycler { /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popObjectIntMap() + * @see org.elasticsearch.common.CacheRecycler#popObjectIntMap() */ @Override @SuppressWarnings({"unchecked"}) @@ -393,7 +382,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushObjectIntMap(gnu.trove.map.hash.TObjectIntHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushObjectIntMap(gnu.trove.map.hash.TObjectIntHashMap) */ @Override public void pushObjectIntMap(TObjectIntHashMap map) { @@ -407,7 +396,7 @@ public class DefaultCacheRecycler implements Recycler { /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popIntObjectMap() + * @see org.elasticsearch.common.CacheRecycler#popIntObjectMap() */ @Override @SuppressWarnings({"unchecked"}) @@ -420,7 +409,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushIntObjectMap(gnu.trove.map.hash.TIntObjectHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushIntObjectMap(gnu.trove.map.hash.TIntObjectHashMap) */ @Override public void pushIntObjectMap(TIntObjectHashMap map) { @@ -433,7 +422,7 @@ public class DefaultCacheRecycler implements Recycler { private final SoftWrapper> objectFloatHashMap = new SoftWrapper>(); /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popObjectFloatMap() + * @see org.elasticsearch.common.CacheRecycler#popObjectFloatMap() */ @Override @SuppressWarnings({"unchecked"}) @@ -446,7 +435,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushObjectFloatMap(gnu.trove.map.hash.TObjectFloatHashMap) + * @see org.elasticsearch.common.CacheRecycler#pushObjectFloatMap(gnu.trove.map.hash.TObjectFloatHashMap) */ @Override public void pushObjectFloatMap(TObjectFloatHashMap map) { @@ -459,7 +448,7 @@ public class DefaultCacheRecycler implements Recycler { private final SoftWrapper> objectArray = new SoftWrapper>(); /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popObjectArray(int) + * @see org.elasticsearch.common.CacheRecycler#popObjectArray(int) */ @Override public Object[] popObjectArray(int size) { @@ -479,7 +468,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#pushObjectArray(java.lang.Object[]) + * @see org.elasticsearch.common.CacheRecycler#pushObjectArray(java.lang.Object[]) */ @Override public void pushObjectArray(Object[] objects) { @@ -491,7 +480,7 @@ public class DefaultCacheRecycler implements Recycler { private final SoftWrapper> intArray = new SoftWrapper>(); /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popIntArray(int) + * @see org.elasticsearch.common.CacheRecycler#popIntArray(int) */ @Override public int[] popIntArray(int size) { @@ -499,7 +488,7 @@ public class DefaultCacheRecycler implements Recycler { } /* (non-Javadoc) - * @see org.elasticsearch.common.Recycler#popIntArray(int, int) + * @see org.elasticsearch.common.CacheRecycler#popIntArray(int, int) */ @Override public int[] popIntArray(int size, int sentinal) { diff --git a/src/main/java/org/elasticsearch/common/NoCacheCacheRecycler.java b/src/main/java/org/elasticsearch/cache/recycler/NoneCacheRecycler.java similarity index 87% rename from src/main/java/org/elasticsearch/common/NoCacheCacheRecycler.java rename to src/main/java/org/elasticsearch/cache/recycler/NoneCacheRecycler.java index d792d47adce..9b4d3d58557 100644 --- a/src/main/java/org/elasticsearch/common/NoCacheCacheRecycler.java +++ b/src/main/java/org/elasticsearch/cache/recycler/NoneCacheRecycler.java @@ -17,27 +17,17 @@ * under the License. */ -package org.elasticsearch.common; +package org.elasticsearch.cache.recycler; -import gnu.trove.map.hash.TByteIntHashMap; -import gnu.trove.map.hash.TDoubleIntHashMap; -import gnu.trove.map.hash.TFloatIntHashMap; -import gnu.trove.map.hash.TIntIntHashMap; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.map.hash.TLongIntHashMap; -import gnu.trove.map.hash.TLongLongHashMap; -import gnu.trove.map.hash.TObjectFloatHashMap; -import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.map.hash.TShortIntHashMap; +import gnu.trove.map.hash.*; import gnu.trove.set.hash.THashSet; - -import java.util.Arrays; - import org.elasticsearch.common.trove.ExtTDoubleObjectHashMap; import org.elasticsearch.common.trove.ExtTHashMap; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; -public class NoCacheCacheRecycler implements Recycler { +import java.util.Arrays; + +public class NoneCacheRecycler implements CacheRecycler { @Override public void clear() { @@ -151,7 +141,7 @@ public class NoCacheCacheRecycler implements Recycler { } @Override - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings({"unchecked"}) public TObjectIntHashMap popObjectIntMap() { return new TObjectIntHashMap(); } @@ -161,7 +151,7 @@ public class NoCacheCacheRecycler implements Recycler { } @Override - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings({"unchecked"}) public TIntObjectHashMap popIntObjectMap() { return new TIntObjectHashMap(); } @@ -171,7 +161,7 @@ public class NoCacheCacheRecycler implements Recycler { } @Override - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings({"unchecked"}) public TObjectFloatHashMap popObjectFloatMap() { return new TObjectFloatHashMap(); } diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/src/main/java/org/elasticsearch/client/transport/TransportClient.java index a0c9989c143..a340729f44b 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -39,21 +39,22 @@ import org.elasticsearch.action.get.MultiGetResponse; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.mlt.MoreLikeThisRequest; -import org.elasticsearch.action.termvector.TermVectorRequest; -import org.elasticsearch.action.termvector.TermVectorResponse; import org.elasticsearch.action.percolate.PercolateRequest; import org.elasticsearch.action.percolate.PercolateResponse; import org.elasticsearch.action.search.*; import org.elasticsearch.action.suggest.SuggestRequest; import org.elasticsearch.action.suggest.SuggestResponse; +import org.elasticsearch.action.termvector.TermVectorRequest; +import org.elasticsearch.action.termvector.TermVectorResponse; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateResponse; +import org.elasticsearch.cache.recycler.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecyclerModule; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.support.AbstractClient; import org.elasticsearch.client.transport.support.InternalTransportClient; import org.elasticsearch.cluster.ClusterNameModule; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.compress.CompressorFactory; @@ -165,6 +166,7 @@ public class TransportClient extends AbstractClient { CompressorFactory.configure(this.settings); ModulesBuilder modules = new ModulesBuilder(); + modules.add(new CacheRecyclerModule(settings)); modules.add(new PluginsModule(this.settings, pluginsService)); modules.add(new EnvironmentModule(environment)); modules.add(new SettingsModule(this.settings)); @@ -272,7 +274,8 @@ public class TransportClient extends AbstractClient { // ignore } - CacheRecycler.clear(); + injector.getInstance(CacheRecycler.class).clear(); + CachedStreams.clear(); ThreadLocals.clearReferencesThreadLocals(); } @@ -431,7 +434,7 @@ public class TransportClient extends AbstractClient { public void moreLikeThis(MoreLikeThisRequest request, ActionListener listener) { internalClient.moreLikeThis(request, listener); } - + @Override public void termVector(TermVectorRequest request, ActionListener listener) { internalClient.termVector(request, listener); diff --git a/src/main/java/org/elasticsearch/common/CacheRecycler.java b/src/main/java/org/elasticsearch/common/CacheRecycler.java deleted file mode 100644 index adf51c1235b..00000000000 --- a/src/main/java/org/elasticsearch/common/CacheRecycler.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.common; - -import gnu.trove.map.hash.*; -import gnu.trove.set.hash.THashSet; - -import org.elasticsearch.common.trove.ExtTDoubleObjectHashMap; -import org.elasticsearch.common.trove.ExtTHashMap; -import org.elasticsearch.common.trove.ExtTLongObjectHashMap; - -public final class CacheRecycler { - - private static final Recycler INSTANCE; - static { - String property = System.getProperty("es.cache.recycle"); - if (property != null && !Boolean.parseBoolean(property)) { - INSTANCE = new NoCacheCacheRecycler(); - } else { - INSTANCE = new DefaultCacheRecycler(); - } - } - - private CacheRecycler() { - // no instance - } - - public static void clear() { - INSTANCE.clear(); - } - - public static ExtTHashMap popHashMap() { - return INSTANCE.popHashMap(); - } - - public static void pushHashMap(ExtTHashMap map) { - INSTANCE.pushHashMap(map); - } - - public static THashSet popHashSet() { - return INSTANCE.popHashSet(); - } - - public static void pushHashSet(THashSet map) { - INSTANCE.pushHashSet(map); - } - - public static ExtTDoubleObjectHashMap popDoubleObjectMap() { - return INSTANCE.popDoubleObjectMap(); - } - - public static void pushDoubleObjectMap(ExtTDoubleObjectHashMap map) { - INSTANCE.pushDoubleObjectMap(map); - } - - public static ExtTLongObjectHashMap popLongObjectMap() { - return INSTANCE.popLongObjectMap(); - } - - public static void pushLongObjectMap(ExtTLongObjectHashMap map) { - INSTANCE.pushLongObjectMap(map); - } - - public static TLongLongHashMap popLongLongMap() { - return INSTANCE.popLongLongMap(); - } - - public static void pushLongLongMap(TLongLongHashMap map) { - INSTANCE.pushLongLongMap(map); - } - - public static TIntIntHashMap popIntIntMap() { - return INSTANCE.popIntIntMap(); - } - - public static void pushIntIntMap(TIntIntHashMap map) { - INSTANCE.pushIntIntMap(map); - } - - public static TFloatIntHashMap popFloatIntMap() { - return INSTANCE.popFloatIntMap(); - } - - public static void pushFloatIntMap(TFloatIntHashMap map) { - INSTANCE.pushFloatIntMap(map); - } - - public static TDoubleIntHashMap popDoubleIntMap() { - return INSTANCE.popDoubleIntMap(); - } - - public static void pushDoubleIntMap(TDoubleIntHashMap map) { - INSTANCE.pushDoubleIntMap(map); - } - - public static TByteIntHashMap popByteIntMap() { - return INSTANCE.popByteIntMap(); - } - - public static void pushByteIntMap(TByteIntHashMap map) { - INSTANCE.pushByteIntMap(map); - } - - public static TShortIntHashMap popShortIntMap() { - return INSTANCE.popShortIntMap(); - } - - public static void pushShortIntMap(TShortIntHashMap map) { - INSTANCE.pushShortIntMap(map); - } - - public static TLongIntHashMap popLongIntMap() { - return INSTANCE.popLongIntMap(); - } - - public static void pushLongIntMap(TLongIntHashMap map) { - INSTANCE.pushLongIntMap(map); - } - - public static TObjectIntHashMap popObjectIntMap() { - return INSTANCE.popObjectIntMap(); - } - - public static void pushObjectIntMap(TObjectIntHashMap map) { - INSTANCE.pushObjectIntMap(map); - } - - public static TIntObjectHashMap popIntObjectMap() { - return INSTANCE.popIntObjectMap(); - } - - public static void pushIntObjectMap(TIntObjectHashMap map) { - INSTANCE.pushIntObjectMap(map); - } - - public static TObjectFloatHashMap popObjectFloatMap() { - return INSTANCE.popObjectFloatMap(); - } - - public static void pushObjectFloatMap(TObjectFloatHashMap map) { - INSTANCE.pushObjectFloatMap(map); - } - - public static Object[] popObjectArray(int size) { - return INSTANCE.popObjectArray(size); - } - - public static void pushObjectArray(Object[] objects) { - INSTANCE.pushObjectArray(objects); - } - - public static int[] popIntArray(int size) { - return INSTANCE.popIntArray(size); - } - - public static int[] popIntArray(int size, int sentinal) { - return INSTANCE.popIntArray(size, sentinal); - } - - public static void pushIntArray(int[] ints) { - INSTANCE.pushIntArray(ints); - } - - public static void pushIntArray(int[] ints, int sentinal) { - INSTANCE.pushIntArray(ints, sentinal); - } - -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java b/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java index d4533e6f7a1..82001e9c0fd 100644 --- a/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java +++ b/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java @@ -24,6 +24,7 @@ import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.apache.lucene.util.CloseableThreadLocal; import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; @@ -69,6 +70,8 @@ public class IndexQueryParserService extends AbstractIndexComponent { } }; + final CacheRecycler cacheRecycler; + final AnalysisService analysisService; final ScriptService scriptService; @@ -92,13 +95,14 @@ public class IndexQueryParserService extends AbstractIndexComponent { @Inject public IndexQueryParserService(Index index, @IndexSettings Settings indexSettings, - IndicesQueriesRegistry indicesQueriesRegistry, + IndicesQueriesRegistry indicesQueriesRegistry, CacheRecycler cacheRecycler, ScriptService scriptService, AnalysisService analysisService, MapperService mapperService, IndexCache indexCache, IndexFieldDataService fieldDataService, IndexEngine indexEngine, @Nullable SimilarityService similarityService, @Nullable Map namedQueryParsers, @Nullable Map namedFilterParsers) { super(index, indexSettings); + this.cacheRecycler = cacheRecycler; this.scriptService = scriptService; this.analysisService = analysisService; this.mapperService = mapperService; diff --git a/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index 438f10badca..eee60fb3b51 100644 --- a/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -26,6 +26,7 @@ import org.apache.lucene.queryparser.classic.QueryParserSettings; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.apache.lucene.search.similarities.Similarity; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.Index; @@ -106,6 +107,10 @@ public class QueryParseContext { return indexQueryParser.analysisService; } + public CacheRecycler cacheRecycler() { + return indexQueryParser.cacheRecycler; + } + public ScriptService scriptService() { return indexQueryParser.scriptService; } diff --git a/src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java b/src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java index 26757b25d17..610ab394ef0 100644 --- a/src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/TopChildrenQueryParser.java @@ -127,7 +127,7 @@ public class TopChildrenQueryParser implements QueryParser { if (searchContext == null) { throw new ElasticSearchIllegalStateException("[top_children] Can't execute, search context not set."); } - TopChildrenQuery childQuery = new TopChildrenQuery(query, childType, parentType, scoreType, factor, incrementalFactor); + TopChildrenQuery childQuery = new TopChildrenQuery(query, childType, parentType, scoreType, factor, incrementalFactor, parseContext.cacheRecycler()); searchContext.addRewrite(childQuery); return childQuery; } diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java index 220f76b5892..6158069b928 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java @@ -30,7 +30,7 @@ import org.apache.lucene.search.*; import org.apache.lucene.util.Bits; import org.apache.lucene.util.ToStringUtils; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.bytes.HashedBytesArray; import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter; import org.elasticsearch.index.cache.id.IdReaderTypeCache; @@ -123,11 +123,11 @@ public class ChildrenQuery extends Query implements SearchContext.Rewrite { public void contextRewrite(SearchContext searchContext) throws Exception { searchContext.idCache().refresh(searchContext.searcher().getTopReaderContext().leaves()); - uidToScore = CacheRecycler.popObjectFloatMap(); + uidToScore = searchContext.cacheRecycler().popObjectFloatMap(); Collector collector; switch (scoreType) { case AVG: - uidToCount = CacheRecycler.popObjectIntMap(); + uidToCount = searchContext.cacheRecycler().popObjectIntMap(); collector = new AvgChildUidCollector(scoreType, searchContext, parentType, uidToScore, uidToCount); break; default: @@ -145,11 +145,11 @@ public class ChildrenQuery extends Query implements SearchContext.Rewrite { @Override public void contextClear() { if (uidToScore != null) { - CacheRecycler.pushObjectFloatMap(uidToScore); + searchContext.cacheRecycler().pushObjectFloatMap(uidToScore); } uidToScore = null; if (uidToCount != null) { - CacheRecycler.pushObjectIntMap(uidToCount); + searchContext.cacheRecycler().pushObjectIntMap(uidToCount); } uidToCount = null; } diff --git a/src/main/java/org/elasticsearch/index/search/child/HasChildFilter.java b/src/main/java/org/elasticsearch/index/search/child/HasChildFilter.java index d2882fc4e3f..84661c28a58 100644 --- a/src/main/java/org/elasticsearch/index/search/child/HasChildFilter.java +++ b/src/main/java/org/elasticsearch/index/search/child/HasChildFilter.java @@ -27,7 +27,6 @@ import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.apache.lucene.util.Bits; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.bytes.HashedBytesArray; import org.elasticsearch.common.lucene.docset.DocIdSets; import org.elasticsearch.common.lucene.docset.MatchDocIdSet; @@ -112,7 +111,7 @@ public class HasChildFilter extends Filter implements SearchContext.Rewrite { @Override public void contextRewrite(SearchContext searchContext) throws Exception { searchContext.idCache().refresh(searchContext.searcher().getTopReaderContext().leaves()); - collectedUids = CacheRecycler.popHashSet(); + collectedUids = searchContext.cacheRecycler().popHashSet(); UidCollector collector = new UidCollector(parentType, searchContext, collectedUids); searchContext.searcher().search(childQuery, collector); } @@ -120,7 +119,7 @@ public class HasChildFilter extends Filter implements SearchContext.Rewrite { @Override public void contextClear() { if (collectedUids != null) { - CacheRecycler.pushHashSet(collectedUids); + searchContext.cacheRecycler().pushHashSet(collectedUids); } collectedUids = null; } @@ -154,7 +153,7 @@ public class HasChildFilter extends Filter implements SearchContext.Rewrite { } @Override - public void collect(int doc, HashedBytesArray parentIdByDoc){ + public void collect(int doc, HashedBytesArray parentIdByDoc) { collectedUids.add(parentIdByDoc); } diff --git a/src/main/java/org/elasticsearch/index/search/child/HasParentFilter.java b/src/main/java/org/elasticsearch/index/search/child/HasParentFilter.java index 264ed1379f8..03cc80524db 100644 --- a/src/main/java/org/elasticsearch/index/search/child/HasParentFilter.java +++ b/src/main/java/org/elasticsearch/index/search/child/HasParentFilter.java @@ -27,7 +27,6 @@ import org.apache.lucene.search.Filter; import org.apache.lucene.search.Query; import org.apache.lucene.util.Bits; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.bytes.HashedBytesArray; import org.elasticsearch.common.lucene.docset.DocIdSets; import org.elasticsearch.common.lucene.docset.MatchDocIdSet; @@ -97,7 +96,7 @@ public class HasParentFilter extends Filter implements SearchContext.Rewrite { @Override public void contextRewrite(SearchContext searchContext) throws Exception { searchContext.idCache().refresh(searchContext.searcher().getTopReaderContext().leaves()); - parents = CacheRecycler.popHashSet(); + parents = context.cacheRecycler().popHashSet(); ParentUidsCollector collector = new ParentUidsCollector(parents, context, parentType); searchContext.searcher().search(parentQuery, collector); parents = collector.collectedUids; @@ -106,7 +105,7 @@ public class HasParentFilter extends Filter implements SearchContext.Rewrite { @Override public void contextClear() { if (parents != null) { - CacheRecycler.pushHashSet(parents); + context.cacheRecycler().pushHashSet(parents); } parents = null; } diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java index 550947d4eaa..cba4e7faca7 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java @@ -27,7 +27,6 @@ import org.apache.lucene.search.*; import org.apache.lucene.util.Bits; import org.apache.lucene.util.ToStringUtils; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter; @@ -64,7 +63,7 @@ public class ParentQuery extends Query implements SearchContext.Rewrite { @Override public void contextRewrite(SearchContext searchContext) throws Exception { searchContext.idCache().refresh(searchContext.searcher().getTopReaderContext().leaves()); - uidToScore = CacheRecycler.popObjectFloatMap(); + uidToScore = searchContext.cacheRecycler().popObjectFloatMap(); ParentUidCollector collector = new ParentUidCollector(uidToScore, searchContext, parentType); Query parentQuery; if (rewrittenParentQuery == null) { @@ -78,7 +77,7 @@ public class ParentQuery extends Query implements SearchContext.Rewrite { @Override public void contextClear() { if (uidToScore != null) { - CacheRecycler.pushObjectFloatMap(uidToScore); + searchContext.cacheRecycler().pushObjectFloatMap(uidToScore); } uidToScore = null; } diff --git a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java index 89d879d7ff9..7f4bbee9309 100644 --- a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java @@ -25,7 +25,7 @@ import org.apache.lucene.search.*; import org.apache.lucene.util.Bits; import org.apache.lucene.util.ToStringUtils; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.bytes.HashedBytesArray; import org.elasticsearch.common.lucene.search.EmptyScorer; import org.elasticsearch.common.trove.ExtTHashMap; @@ -53,6 +53,7 @@ import java.util.Set; */ public class TopChildrenQuery extends Query implements SearchContext.Rewrite { + private final CacheRecycler cacheRecycler; private final String parentType; private final String childType; private final ScoreType scoreType; @@ -65,13 +66,14 @@ public class TopChildrenQuery extends Query implements SearchContext.Rewrite { private ExtTHashMap parentDocs; // Note, the query is expected to already be filtered to only child type docs - public TopChildrenQuery(Query childQuery, String childType, String parentType, ScoreType scoreType, int factor, int incrementalFactor) { + public TopChildrenQuery(Query childQuery, String childType, String parentType, ScoreType scoreType, int factor, int incrementalFactor, CacheRecycler cacheRecycler) { this.originalChildQuery = childQuery; this.childType = childType; this.parentType = parentType; this.scoreType = scoreType; this.factor = factor; this.incrementalFactor = incrementalFactor; + this.cacheRecycler = cacheRecycler; } // Rewrite invocation logic: @@ -92,7 +94,7 @@ public class TopChildrenQuery extends Query implements SearchContext.Rewrite { @Override public void contextRewrite(SearchContext searchContext) throws Exception { - this.parentDocs = CacheRecycler.popHashMap(); + this.parentDocs = cacheRecycler.popHashMap(); searchContext.idCache().refresh(searchContext.searcher().getTopReaderContext().leaves()); int parentHitsResolved; @@ -132,14 +134,14 @@ public class TopChildrenQuery extends Query implements SearchContext.Rewrite { @Override public void contextClear() { if (parentDocs != null) { - CacheRecycler.pushHashMap(parentDocs); + cacheRecycler.pushHashMap(parentDocs); parentDocs = null; } } int resolveParentDocuments(TopDocs topDocs, SearchContext context) { int parentHitsResolved = 0; - ExtTHashMap> parentDocsPerReader = CacheRecycler.popHashMap(); + ExtTHashMap> parentDocsPerReader = cacheRecycler.popHashMap(); for (ScoreDoc scoreDoc : topDocs.scoreDocs) { int readerIndex = ReaderUtil.subIndex(scoreDoc.doc, context.searcher().getIndexReader().leaves()); AtomicReaderContext subContext = context.searcher().getIndexReader().leaves().get(readerIndex); @@ -161,7 +163,7 @@ public class TopChildrenQuery extends Query implements SearchContext.Rewrite { TIntObjectHashMap readerParentDocs = parentDocsPerReader.get(indexReader.getCoreCacheKey()); if (readerParentDocs == null) { - readerParentDocs = CacheRecycler.popIntObjectMap(); + readerParentDocs = cacheRecycler.popIntObjectMap(); parentDocsPerReader.put(indexReader.getCoreCacheKey(), readerParentDocs); } @@ -189,9 +191,9 @@ public class TopChildrenQuery extends Query implements SearchContext.Rewrite { ParentDoc[] values = entry.getValue().values(new ParentDoc[entry.getValue().size()]); Arrays.sort(values, PARENT_DOC_COMP); parentDocs.put(entry.getKey(), values); - CacheRecycler.pushIntObjectMap(entry.getValue()); + cacheRecycler.pushIntObjectMap(entry.getValue()); } - CacheRecycler.pushHashMap(parentDocsPerReader); + cacheRecycler.pushHashMap(parentDocsPerReader); return parentHitsResolved; } diff --git a/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java b/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java index 0a4e1c209ee..c485e7e7679 100644 --- a/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java +++ b/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java @@ -26,7 +26,7 @@ import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalNotification; import gnu.trove.set.hash.THashSet; import org.apache.lucene.search.DocIdSet; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit; public class IndicesFilterCache extends AbstractComponent implements RemovalListener { private final ThreadPool threadPool; + private final CacheRecycler cacheRecycler; private Cache cache; @@ -88,9 +89,10 @@ public class IndicesFilterCache extends AbstractComponent implements RemovalList } @Inject - public IndicesFilterCache(Settings settings, ThreadPool threadPool, NodeSettingsService nodeSettingsService) { + public IndicesFilterCache(Settings settings, ThreadPool threadPool, CacheRecycler cacheRecycler, NodeSettingsService nodeSettingsService) { super(settings); this.threadPool = threadPool; + this.cacheRecycler = cacheRecycler; this.size = componentSettings.get("size", "20%"); this.expire = componentSettings.getAsTime("expire", null); this.cleanInterval = componentSettings.getAsTime("clean_interval", TimeValue.timeValueSeconds(60)); @@ -172,7 +174,7 @@ public class IndicesFilterCache extends AbstractComponent implements RemovalList threadPool.executor(ThreadPool.Names.GENERIC).execute(new Runnable() { @Override public void run() { - THashSet keys = CacheRecycler.popHashSet(); + THashSet keys = cacheRecycler.popHashSet(); try { for (Iterator it = readersKeysToClean.iterator(); it.hasNext(); ) { keys.add(it.next()); @@ -190,7 +192,7 @@ public class IndicesFilterCache extends AbstractComponent implements RemovalList } threadPool.schedule(cleanInterval, ThreadPool.Names.SAME, ReaderCleaner.this); } finally { - CacheRecycler.pushHashSet(keys); + cacheRecycler.pushHashSet(keys); } } }); diff --git a/src/main/java/org/elasticsearch/node/internal/InternalNode.java b/src/main/java/org/elasticsearch/node/internal/InternalNode.java index 6b663cf7685..1e295cf29ea 100644 --- a/src/main/java/org/elasticsearch/node/internal/InternalNode.java +++ b/src/main/java/org/elasticsearch/node/internal/InternalNode.java @@ -26,6 +26,8 @@ import org.elasticsearch.bulk.udp.BulkUdpModule; import org.elasticsearch.bulk.udp.BulkUdpService; import org.elasticsearch.cache.NodeCache; import org.elasticsearch.cache.NodeCacheModule; +import org.elasticsearch.cache.recycler.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecyclerModule; import org.elasticsearch.client.Client; import org.elasticsearch.client.node.NodeClientModule; import org.elasticsearch.cluster.ClusterModule; @@ -33,7 +35,6 @@ import org.elasticsearch.cluster.ClusterNameModule; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.routing.RoutingService; import org.elasticsearch.cluster.routing.allocation.AllocationService; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.StopWatch; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.component.Lifecycle; @@ -134,6 +135,7 @@ public final class InternalNode implements Node { NodeEnvironment nodeEnvironment = new NodeEnvironment(this.settings, this.environment); ModulesBuilder modules = new ModulesBuilder(); + modules.add(new CacheRecyclerModule(settings)); modules.add(new PluginsModule(settings, pluginsService)); modules.add(new SettingsModule(settings)); modules.add(new NodeModule(this)); @@ -344,9 +346,9 @@ public final class InternalNode implements Node { } injector.getInstance(NodeEnvironment.class).close(); + injector.getInstance(CacheRecycler.class).clear(); Injectors.close(injector); - CacheRecycler.clear(); CachedStreams.clear(); ThreadLocals.clearReferencesThreadLocals(); diff --git a/src/main/java/org/elasticsearch/search/SearchService.java b/src/main/java/org/elasticsearch/search/SearchService.java index 5c4354a79bb..dff5f0fb3d3 100644 --- a/src/main/java/org/elasticsearch/search/SearchService.java +++ b/src/main/java/org/elasticsearch/search/SearchService.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap; import org.apache.lucene.search.TopDocs; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Nullable; @@ -80,6 +81,8 @@ public class SearchService extends AbstractLifecycleComponent { private final ScriptService scriptService; + private final CacheRecycler cacheRecycler; + private final DfsPhase dfsPhase; private final QueryPhase queryPhase; @@ -102,13 +105,14 @@ public class SearchService extends AbstractLifecycleComponent { @Inject public SearchService(Settings settings, ClusterService clusterService, IndicesService indicesService, IndicesLifecycle indicesLifecycle, IndicesWarmer indicesWarmer, ThreadPool threadPool, - ScriptService scriptService, DfsPhase dfsPhase, QueryPhase queryPhase, FetchPhase fetchPhase) { + ScriptService scriptService, CacheRecycler cacheRecycler, DfsPhase dfsPhase, QueryPhase queryPhase, FetchPhase fetchPhase) { super(settings); this.threadPool = threadPool; this.clusterService = clusterService; this.indicesService = indicesService; this.indicesWarmer = indicesWarmer; this.scriptService = scriptService; + this.cacheRecycler = cacheRecycler; this.dfsPhase = dfsPhase; this.queryPhase = queryPhase; this.fetchPhase = fetchPhase; @@ -476,7 +480,7 @@ public class SearchService extends AbstractLifecycleComponent { SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), request.index(), request.shardId()); Engine.Searcher engineSearcher = searcher == null ? indexShard.searcher() : searcher; - SearchContext context = new SearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, indexService, indexShard, scriptService); + SearchContext context = new SearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, indexService, indexShard, scriptService, cacheRecycler); SearchContext.setCurrent(context); try { context.scroll(request.scroll()); diff --git a/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java b/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java index 60bca7cb22b..392c1a26b85 100644 --- a/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java +++ b/src/main/java/org/elasticsearch/search/controller/SearchPhaseController.java @@ -25,6 +25,7 @@ import com.google.common.collect.Ordering; import org.apache.lucene.index.Term; import org.apache.lucene.search.*; import org.apache.lucene.util.PriorityQueue; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.XMaps; import org.elasticsearch.common.component.AbstractComponent; @@ -71,11 +72,13 @@ public class SearchPhaseController extends AbstractComponent { private static final ShardDoc[] EMPTY = new ShardDoc[0]; + private final CacheRecycler cacheRecycler; private final boolean optimizeSingleShard; @Inject - public SearchPhaseController(Settings settings) { + public SearchPhaseController(Settings settings, CacheRecycler cacheRecycler) { super(settings); + this.cacheRecycler = cacheRecycler; this.optimizeSingleShard = componentSettings.getAsBoolean("optimize_single_shard", true); } @@ -327,7 +330,7 @@ public class SearchPhaseController extends AbstractComponent { } } if (!namedFacets.isEmpty()) { - Facet aggregatedFacet = ((InternalFacet) namedFacets.get(0)).reduce(namedFacets); + Facet aggregatedFacet = ((InternalFacet) namedFacets.get(0)).reduce(new InternalFacet.ReduceContext(cacheRecycler, namedFacets)); aggregatedFacets.add(aggregatedFacet); } } diff --git a/src/main/java/org/elasticsearch/search/facet/InternalFacet.java b/src/main/java/org/elasticsearch/search/facet/InternalFacet.java index 0026196d820..a261aef2f13 100644 --- a/src/main/java/org/elasticsearch/search/facet/InternalFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/InternalFacet.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.facet; import com.google.common.collect.ImmutableMap; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.io.stream.StreamInput; @@ -35,6 +36,24 @@ import java.util.List; */ public abstract class InternalFacet implements Facet, Streamable, ToXContent { + public static class ReduceContext { + private final CacheRecycler cacheRecycler; + private final List facets; + + public ReduceContext(CacheRecycler cacheRecycler, List facets) { + this.cacheRecycler = cacheRecycler; + this.facets = facets; + } + + public CacheRecycler cacheRecycler() { + return cacheRecycler; + } + + public List facets() { + return facets; + } + } + private String facetName; /** @@ -50,7 +69,7 @@ public abstract class InternalFacet implements Facet, Streamable, ToXContent { public abstract BytesReference streamType(); - public abstract Facet reduce(List facets); + public abstract Facet reduce(ReduceContext context); public static interface Stream { Facet readFacet(StreamInput in) throws IOException; diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetExecutor.java index b1ef4169b48..95e239f23c4 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetExecutor.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.facet.datehistogram; import gnu.trove.map.hash.TLongLongHashMap; import org.apache.lucene.index.AtomicReaderContext; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.joda.TimeZoneRounding; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.LongValues; @@ -37,18 +37,20 @@ import java.io.IOException; */ public class CountDateHistogramFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final TimeZoneRounding tzRounding; private final IndexNumericFieldData indexFieldData; final DateHistogramFacet.ComparatorType comparatorType; final TLongLongHashMap counts; - public CountDateHistogramFacetExecutor(IndexNumericFieldData indexFieldData, TimeZoneRounding tzRounding, DateHistogramFacet.ComparatorType comparatorType) { + public CountDateHistogramFacetExecutor(IndexNumericFieldData indexFieldData, TimeZoneRounding tzRounding, DateHistogramFacet.ComparatorType comparatorType, CacheRecycler cacheRecycler) { this.comparatorType = comparatorType; this.indexFieldData = indexFieldData; this.tzRounding = tzRounding; + this.cacheRecycler = cacheRecycler; - this.counts = CacheRecycler.popLongLongMap(); + this.counts = cacheRecycler.popLongLongMap(); } @Override @@ -58,7 +60,7 @@ public class CountDateHistogramFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { - return new InternalCountDateHistogramFacet(facetName, comparatorType, counts, true); + return new InternalCountDateHistogramFacet(facetName, comparatorType, counts, cacheRecycler); } class Collector extends FacetExecutor.Collector { diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetParser.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetParser.java index d2897626c89..3b874191608 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetParser.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/DateHistogramFacetParser.java @@ -179,16 +179,16 @@ public class DateHistogramFacetParser extends AbstractComponent implements Facet if (valueScript != null) { SearchScript script = context.scriptService().search(context.lookup(), scriptLang, valueScript, params); - return new ValueScriptDateHistogramFacetExecutor(keyIndexFieldData, script, tzRounding, comparatorType); + return new ValueScriptDateHistogramFacetExecutor(keyIndexFieldData, script, tzRounding, comparatorType, context.cacheRecycler()); } else if (valueField != null) { FieldMapper valueMapper = context.smartNameFieldMapper(valueField); if (valueMapper == null) { throw new FacetPhaseExecutionException(facetName, "(value) field [" + valueField + "] not found"); } IndexNumericFieldData valueIndexFieldData = context.fieldData().getForField(valueMapper); - return new ValueDateHistogramFacetExecutor(keyIndexFieldData, valueIndexFieldData, tzRounding, comparatorType); + return new ValueDateHistogramFacetExecutor(keyIndexFieldData, valueIndexFieldData, tzRounding, comparatorType, context.cacheRecycler()); } else { - return new CountDateHistogramFacetExecutor(keyIndexFieldData, tzRounding, comparatorType); + return new CountDateHistogramFacetExecutor(keyIndexFieldData, tzRounding, comparatorType, context.cacheRecycler()); } } diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalCountDateHistogramFacet.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalCountDateHistogramFacet.java index 4e23b38412f..ec0172f0ae8 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalCountDateHistogramFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalCountDateHistogramFacet.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.facet.datehistogram; import gnu.trove.iterator.TLongLongIterator; import gnu.trove.map.hash.TLongLongHashMap; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; @@ -108,24 +108,30 @@ public class InternalCountDateHistogramFacet extends InternalDateHistogramFacet } } - private ComparatorType comparatorType; + ComparatorType comparatorType; TLongLongHashMap counts; - boolean cachedCounts; + CacheRecycler cacheRecycler; CountEntry[] entries = null; - private InternalCountDateHistogramFacet() { + InternalCountDateHistogramFacet() { } - public InternalCountDateHistogramFacet(String name, ComparatorType comparatorType, TLongLongHashMap counts, boolean cachedCounts) { + public InternalCountDateHistogramFacet(String name, ComparatorType comparatorType, TLongLongHashMap counts, CacheRecycler cacheRecycler) { super(name); this.comparatorType = comparatorType; this.counts = counts; - this.cachedCounts = cachedCounts; + this.cacheRecycler = cacheRecycler; + } + + public InternalCountDateHistogramFacet(String name, ComparatorType comparatorType, CountEntry[] entries) { + super(name); + this.comparatorType = comparatorType; + this.entries = entries; } @Override public List getEntries() { - return Arrays.asList(computeEntries()); + return Arrays.asList(entries); } @Override @@ -134,46 +140,58 @@ public class InternalCountDateHistogramFacet extends InternalDateHistogramFacet } void releaseCache() { - if (cachedCounts) { - CacheRecycler.pushLongLongMap(counts); - cachedCounts = false; + if (cacheRecycler != null) { + cacheRecycler.pushLongLongMap(counts); + cacheRecycler = null; counts = null; } } - private CountEntry[] computeEntries() { - if (entries != null) { - return entries; + @Override + public Facet reduce(ReduceContext context) { + List facets = context.facets(); + if (facets.size() == 1) { + InternalCountDateHistogramFacet histoFacet = (InternalCountDateHistogramFacet) facets.get(0); + if (histoFacet.entries == null) { + histoFacet.entries = new CountEntry[histoFacet.counts.size()]; + int i = 0; + for (TLongLongIterator it = histoFacet.counts.iterator(); it.hasNext(); ) { + it.advance(); + histoFacet.entries[i++] = new CountEntry(it.key(), it.value()); + } + } + Arrays.sort(histoFacet.entries, histoFacet.comparatorType.comparator()); + histoFacet.releaseCache(); + return facets.get(0); } - entries = new CountEntry[counts.size()]; + + TLongLongHashMap counts = context.cacheRecycler().popLongLongMap(); + for (Facet facet : facets) { + InternalCountDateHistogramFacet histoFacet = (InternalCountDateHistogramFacet) facet; + if (histoFacet.entries != null) { + for (CountEntry entry : histoFacet.entries) { + counts.adjustOrPutValue(entry.getTime(), entry.getCount(), entry.getCount()); + } + } else { + for (TLongLongIterator it = histoFacet.counts.iterator(); it.hasNext(); ) { + it.advance(); + counts.adjustOrPutValue(it.key(), it.value(), it.value()); + } + } + histoFacet.releaseCache(); + } + + CountEntry[] entries = new CountEntry[counts.size()]; int i = 0; for (TLongLongIterator it = counts.iterator(); it.hasNext(); ) { it.advance(); entries[i++] = new CountEntry(it.key(), it.value()); } - releaseCache(); + context.cacheRecycler().pushLongLongMap(counts); + Arrays.sort(entries, comparatorType.comparator()); - return entries; - } - @Override - public Facet reduce(List facets) { - if (facets.size() == 1) { - return facets.get(0); - } - TLongLongHashMap counts = CacheRecycler.popLongLongMap(); - - for (Facet facet : facets) { - InternalCountDateHistogramFacet histoFacet = (InternalCountDateHistogramFacet) facet; - for (TLongLongIterator it = histoFacet.counts.iterator(); it.hasNext(); ) { - it.advance(); - counts.adjustOrPutValue(it.key(), it.value(), it.value()); - } - histoFacet.releaseCache(); - - } - - return new InternalCountDateHistogramFacet(getName(), comparatorType, counts, true); + return new InternalCountDateHistogramFacet(getName(), comparatorType, entries); } static final class Fields { @@ -188,7 +206,7 @@ public class InternalCountDateHistogramFacet extends InternalDateHistogramFacet builder.startObject(getName()); builder.field(Fields._TYPE, TYPE); builder.startArray(Fields.ENTRIES); - for (Entry entry : computeEntries()) { + for (Entry entry : entries) { builder.startObject(); builder.field(Fields.TIME, entry.getTime()); builder.field(Fields.COUNT, entry.getCount()); @@ -211,11 +229,9 @@ public class InternalCountDateHistogramFacet extends InternalDateHistogramFacet comparatorType = ComparatorType.fromId(in.readByte()); int size = in.readVInt(); - counts = CacheRecycler.popLongLongMap(); - cachedCounts = true; + entries = new CountEntry[size]; for (int i = 0; i < size; i++) { - long key = in.readLong(); - counts.put(key, in.readVLong()); + entries[i] = new CountEntry(in.readLong(), in.readVLong()); } } @@ -223,11 +239,19 @@ public class InternalCountDateHistogramFacet extends InternalDateHistogramFacet public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeByte(comparatorType.id()); - out.writeVInt(counts.size()); - for (TLongLongIterator it = counts.iterator(); it.hasNext(); ) { - it.advance(); - out.writeLong(it.key()); - out.writeVLong(it.value()); + if (entries != null) { + out.writeVInt(entries.length); + for (CountEntry entry : entries) { + out.writeLong(entry.getTime()); + out.writeVLong(entry.getCount()); + } + } else { + out.writeVInt(counts.size()); + for (TLongLongIterator it = counts.iterator(); it.hasNext(); ) { + it.advance(); + out.writeLong(it.key()); + out.writeVLong(it.value()); + } } releaseCache(); } diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalFullDateHistogramFacet.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalFullDateHistogramFacet.java index 418f3c36d4d..df5d7d8b5b8 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalFullDateHistogramFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalFullDateHistogramFacet.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.facet.datehistogram; import org.apache.lucene.util.CollectionUtil; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; @@ -119,7 +119,7 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet { private ComparatorType comparatorType; ExtTLongObjectHashMap tEntries; - boolean cachedEntries; + CacheRecycler cacheRecycler; Collection entries; InternalFullDateHistogramFacet() { @@ -129,11 +129,11 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet { super(name); } - public InternalFullDateHistogramFacet(String name, ComparatorType comparatorType, ExtTLongObjectHashMap entries, boolean cachedEntries) { + public InternalFullDateHistogramFacet(String name, ComparatorType comparatorType, ExtTLongObjectHashMap entries, CacheRecycler cacheRecycler) { super(name); this.comparatorType = comparatorType; this.tEntries = entries; - this.cachedEntries = cachedEntries; + this.cacheRecycler = cacheRecycler; this.entries = entries.valueCollection(); } @@ -151,15 +151,16 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet { } void releaseCache() { - if (cachedEntries) { - CacheRecycler.pushLongObjectMap(tEntries); - cachedEntries = false; + if (cacheRecycler != null) { + cacheRecycler.pushLongObjectMap(tEntries); + cacheRecycler = null; tEntries = null; } } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { // we need to sort it InternalFullDateHistogramFacet internalFacet = (InternalFullDateHistogramFacet) facets.get(0); @@ -169,7 +170,7 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet { return internalFacet; } - ExtTLongObjectHashMap map = CacheRecycler.popLongObjectMap(); + ExtTLongObjectHashMap map = context.cacheRecycler().popLongObjectMap(); for (Facet facet : facets) { InternalFullDateHistogramFacet histoFacet = (InternalFullDateHistogramFacet) facet; @@ -204,7 +205,7 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet { ordered.add(value); } - CacheRecycler.pushLongObjectMap(map); + context.cacheRecycler().pushLongObjectMap(map); // just initialize it as already ordered facet InternalFullDateHistogramFacet ret = new InternalFullDateHistogramFacet(getName()); @@ -256,8 +257,6 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet { public void readFrom(StreamInput in) throws IOException { super.readFrom(in); comparatorType = ComparatorType.fromId(in.readByte()); - - cachedEntries = false; int size = in.readVInt(); entries = new ArrayList(size); for (int i = 0; i < size; i++) { diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetExecutor.java index 4cfc78d04af..c079d0e20de 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetExecutor.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.facet.datehistogram; import org.apache.lucene.index.AtomicReaderContext; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.joda.TimeZoneRounding; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; import org.elasticsearch.index.fielddata.DoubleValues; @@ -38,6 +38,7 @@ import java.io.IOException; */ public class ValueDateHistogramFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final IndexNumericFieldData keyIndexFieldData; private final IndexNumericFieldData valueIndexFieldData; private final DateHistogramFacet.ComparatorType comparatorType; @@ -45,13 +46,14 @@ public class ValueDateHistogramFacetExecutor extends FacetExecutor { final ExtTLongObjectHashMap entries; - public ValueDateHistogramFacetExecutor(IndexNumericFieldData keyIndexFieldData, IndexNumericFieldData valueIndexFieldData, TimeZoneRounding tzRounding, DateHistogramFacet.ComparatorType comparatorType) { + public ValueDateHistogramFacetExecutor(IndexNumericFieldData keyIndexFieldData, IndexNumericFieldData valueIndexFieldData, TimeZoneRounding tzRounding, DateHistogramFacet.ComparatorType comparatorType, CacheRecycler cacheRecycler) { this.comparatorType = comparatorType; this.keyIndexFieldData = keyIndexFieldData; this.valueIndexFieldData = valueIndexFieldData; this.tzRounding = tzRounding; + this.cacheRecycler = cacheRecycler; - this.entries = CacheRecycler.popLongObjectMap(); + this.entries = cacheRecycler.popLongObjectMap(); } @Override @@ -61,7 +63,7 @@ public class ValueDateHistogramFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { - return new InternalFullDateHistogramFacet(facetName, comparatorType, entries, true); + return new InternalFullDateHistogramFacet(facetName, comparatorType, entries, cacheRecycler); } class Collector extends FacetExecutor.Collector { diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetExecutor.java index 33977a897e7..421fe4ea97e 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetExecutor.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.facet.datehistogram; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.joda.TimeZoneRounding; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; import org.elasticsearch.index.fielddata.IndexNumericFieldData; @@ -39,6 +39,7 @@ import java.io.IOException; */ public class ValueScriptDateHistogramFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final IndexNumericFieldData keyIndexFieldData; private final DateHistogramFacet.ComparatorType comparatorType; final SearchScript valueScript; @@ -46,13 +47,14 @@ public class ValueScriptDateHistogramFacetExecutor extends FacetExecutor { final ExtTLongObjectHashMap entries; - public ValueScriptDateHistogramFacetExecutor(IndexNumericFieldData keyIndexFieldData, SearchScript valueScript, TimeZoneRounding tzRounding, DateHistogramFacet.ComparatorType comparatorType) { + public ValueScriptDateHistogramFacetExecutor(IndexNumericFieldData keyIndexFieldData, SearchScript valueScript, TimeZoneRounding tzRounding, DateHistogramFacet.ComparatorType comparatorType, CacheRecycler cacheRecycler) { this.comparatorType = comparatorType; this.keyIndexFieldData = keyIndexFieldData; this.valueScript = valueScript; this.tzRounding = tzRounding; + this.cacheRecycler = cacheRecycler; - this.entries = CacheRecycler.popLongObjectMap(); + this.entries = cacheRecycler.popLongObjectMap(); } @Override @@ -62,7 +64,7 @@ public class ValueScriptDateHistogramFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { - return new InternalFullDateHistogramFacet(facetName, comparatorType, entries, true); + return new InternalFullDateHistogramFacet(facetName, comparatorType, entries, cacheRecycler); } class Collector extends FacetExecutor.Collector { diff --git a/src/main/java/org/elasticsearch/search/facet/filter/InternalFilterFacet.java b/src/main/java/org/elasticsearch/search/facet/filter/InternalFilterFacet.java index 1697874d211..c0778567738 100644 --- a/src/main/java/org/elasticsearch/search/facet/filter/InternalFilterFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/filter/InternalFilterFacet.java @@ -78,7 +78,8 @@ public class InternalFilterFacet extends InternalFacet implements FilterFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { return facets.get(0); } diff --git a/src/main/java/org/elasticsearch/search/facet/geodistance/InternalGeoDistanceFacet.java b/src/main/java/org/elasticsearch/search/facet/geodistance/InternalGeoDistanceFacet.java index 3885377ac0e..5f8f9d6c36d 100644 --- a/src/main/java/org/elasticsearch/search/facet/geodistance/InternalGeoDistanceFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/geodistance/InternalGeoDistanceFacet.java @@ -83,8 +83,8 @@ public class InternalGeoDistanceFacet extends InternalFacet implements GeoDistan return getEntries().iterator(); } - @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { return facets.get(0); } diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetExecutor.java index ad36a10833f..5ea92bb4a7e 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetExecutor.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.facet.histogram; import gnu.trove.map.hash.TLongLongHashMap; import org.apache.lucene.index.AtomicReaderContext; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.index.fielddata.DoubleValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.search.facet.DoubleFacetAggregatorBase; @@ -37,6 +37,7 @@ import java.io.IOException; */ public class CountHistogramFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final IndexNumericFieldData indexFieldData; private final HistogramFacet.ComparatorType comparatorType; final long interval; @@ -47,8 +48,9 @@ public class CountHistogramFacetExecutor extends FacetExecutor { this.comparatorType = comparatorType; this.indexFieldData = indexFieldData; this.interval = interval; + this.cacheRecycler = context.cacheRecycler(); - this.counts = CacheRecycler.popLongLongMap(); + this.counts = cacheRecycler.popLongLongMap(); } @Override @@ -58,7 +60,7 @@ public class CountHistogramFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { - return new InternalCountHistogramFacet(facetName, comparatorType, counts, true); + return new InternalCountHistogramFacet(facetName, comparatorType, counts, cacheRecycler); } public static long bucket(double value, long interval) { diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/FullHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/FullHistogramFacetExecutor.java index 9d7699ed7b2..7f9b22b2ab3 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/FullHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/FullHistogramFacetExecutor.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.facet.histogram; import org.apache.lucene.index.AtomicReaderContext; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; import org.elasticsearch.index.fielddata.DoubleValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; @@ -37,6 +37,7 @@ import java.io.IOException; */ public class FullHistogramFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final IndexNumericFieldData indexFieldData; private final HistogramFacet.ComparatorType comparatorType; final long interval; @@ -47,8 +48,9 @@ public class FullHistogramFacetExecutor extends FacetExecutor { this.comparatorType = comparatorType; this.indexFieldData = indexFieldData; this.interval = interval; + this.cacheRecycler = context.cacheRecycler(); - this.entries = CacheRecycler.popLongObjectMap(); + this.entries = cacheRecycler.popLongObjectMap(); } @Override @@ -58,7 +60,7 @@ public class FullHistogramFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { - return new InternalFullHistogramFacet(facetName, comparatorType, entries, true); + return new InternalFullHistogramFacet(facetName, comparatorType, entries, cacheRecycler); } public static long bucket(double value, long interval) { diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/InternalCountHistogramFacet.java b/src/main/java/org/elasticsearch/search/facet/histogram/InternalCountHistogramFacet.java index 5e46a29d6e8..03f0894526a 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/InternalCountHistogramFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/InternalCountHistogramFacet.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.facet.histogram; import gnu.trove.iterator.TLongLongIterator; import gnu.trove.map.hash.TLongLongHashMap; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; @@ -110,22 +110,28 @@ public class InternalCountHistogramFacet extends InternalHistogramFacet { ComparatorType comparatorType; TLongLongHashMap counts; - boolean cachedCounts; + CacheRecycler cacheRecycler; CountEntry[] entries = null; private InternalCountHistogramFacet() { } - public InternalCountHistogramFacet(String name, ComparatorType comparatorType, TLongLongHashMap counts, boolean cachedCounts) { + public InternalCountHistogramFacet(String name, ComparatorType comparatorType, TLongLongHashMap counts, CacheRecycler cacheRecycler) { super(name); this.comparatorType = comparatorType; this.counts = counts; - this.cachedCounts = cachedCounts; + this.cacheRecycler = cacheRecycler; + } + + public InternalCountHistogramFacet(String name, ComparatorType comparatorType, CountEntry[] entries) { + super(name); + this.comparatorType = comparatorType; + this.entries = entries; } @Override public List getEntries() { - return Arrays.asList(computeEntries()); + return Arrays.asList(entries); } @Override @@ -133,46 +139,59 @@ public class InternalCountHistogramFacet extends InternalHistogramFacet { return (Iterator) getEntries().iterator(); } - private CountEntry[] computeEntries() { - if (entries != null) { - return entries; - } - entries = new CountEntry[counts.size()]; - int i = 0; - for (TLongLongIterator it = counts.iterator(); it.hasNext(); ) { - it.advance(); - entries[i++] = new CountEntry(it.key(), it.value()); - } - releaseCache(); - Arrays.sort(entries, comparatorType.comparator()); - return entries; - } - void releaseCache() { - if (cachedCounts) { - CacheRecycler.pushLongLongMap(counts); - cachedCounts = false; + if (cacheRecycler != null) { + cacheRecycler.pushLongLongMap(counts); + cacheRecycler = null; counts = null; } } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { + // need to sort here... + InternalCountHistogramFacet histoFacet = (InternalCountHistogramFacet) facets.get(0); + if (histoFacet.entries == null) { + histoFacet.entries = new CountEntry[histoFacet.counts.size()]; + int i = 0; + for (TLongLongIterator it = histoFacet.counts.iterator(); it.hasNext(); ) { + it.advance(); + histoFacet.entries[i++] = new CountEntry(it.key(), it.value()); + } + } + Arrays.sort(histoFacet.entries, histoFacet.comparatorType.comparator()); + histoFacet.releaseCache(); return facets.get(0); } - TLongLongHashMap counts = CacheRecycler.popLongLongMap(); + TLongLongHashMap counts = context.cacheRecycler().popLongLongMap(); for (Facet facet : facets) { InternalCountHistogramFacet histoFacet = (InternalCountHistogramFacet) facet; - for (TLongLongIterator it = histoFacet.counts.iterator(); it.hasNext(); ) { - it.advance(); - counts.adjustOrPutValue(it.key(), it.value(), it.value()); + if (histoFacet.entries != null) { + for (Entry entry : histoFacet.entries) { + counts.adjustOrPutValue(entry.getKey(), entry.getCount(), entry.getCount()); + } + } else { + for (TLongLongIterator it = histoFacet.counts.iterator(); it.hasNext(); ) { + it.advance(); + counts.adjustOrPutValue(it.key(), it.value(), it.value()); + } } histoFacet.releaseCache(); } + CountEntry[] entries = new CountEntry[counts.size()]; + int i = 0; + for (TLongLongIterator it = counts.iterator(); it.hasNext(); ) { + it.advance(); + entries[i++] = new CountEntry(it.key(), it.value()); + } + context.cacheRecycler().pushLongLongMap(counts); - return new InternalCountHistogramFacet(getName(), comparatorType, counts, true); + Arrays.sort(entries, comparatorType.comparator()); + + return new InternalCountHistogramFacet(getName(), comparatorType, entries); } static final class Fields { @@ -187,7 +206,7 @@ public class InternalCountHistogramFacet extends InternalHistogramFacet { builder.startObject(getName()); builder.field(Fields._TYPE, HistogramFacet.TYPE); builder.startArray(Fields.ENTRIES); - for (Entry entry : computeEntries()) { + for (Entry entry : entries) { builder.startObject(); builder.field(Fields.KEY, entry.getKey()); builder.field(Fields.COUNT, entry.getCount()); @@ -208,13 +227,10 @@ public class InternalCountHistogramFacet extends InternalHistogramFacet { public void readFrom(StreamInput in) throws IOException { super.readFrom(in); comparatorType = ComparatorType.fromId(in.readByte()); - int size = in.readVInt(); - counts = CacheRecycler.popLongLongMap(); - cachedCounts = true; + entries = new CountEntry[size]; for (int i = 0; i < size; i++) { - long key = in.readLong(); - counts.put(key, in.readVLong()); + entries[i] = new CountEntry(in.readLong(), in.readVLong()); } } @@ -222,12 +238,20 @@ public class InternalCountHistogramFacet extends InternalHistogramFacet { public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeByte(comparatorType.id()); - // optimize the write, since we know we have the same buckets as keys - out.writeVInt(counts.size()); - for (TLongLongIterator it = counts.iterator(); it.hasNext(); ) { - it.advance(); - out.writeLong(it.key()); - out.writeVLong(it.value()); + if (entries != null) { + out.writeVInt(entries.length); + for (CountEntry entry : entries) { + out.writeLong(entry.getKey()); + out.writeVLong(entry.getCount()); + } + } else { + // optimize the write, since we know we have the same buckets as keys + out.writeVInt(counts.size()); + for (TLongLongIterator it = counts.iterator(); it.hasNext(); ) { + it.advance(); + out.writeLong(it.key()); + out.writeVLong(it.value()); + } } releaseCache(); } diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/InternalFullHistogramFacet.java b/src/main/java/org/elasticsearch/search/facet/histogram/InternalFullHistogramFacet.java index db95bfa4ad2..6f6b04132ea 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/InternalFullHistogramFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/InternalFullHistogramFacet.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.facet.histogram; import org.apache.lucene.util.CollectionUtil; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; @@ -116,7 +116,7 @@ public class InternalFullHistogramFacet extends InternalHistogramFacet { private ComparatorType comparatorType; ExtTLongObjectHashMap tEntries; - boolean cachedEntries; + CacheRecycler cacheRecycler; Collection entries; InternalFullHistogramFacet() { @@ -126,11 +126,11 @@ public class InternalFullHistogramFacet extends InternalHistogramFacet { super(name); } - public InternalFullHistogramFacet(String name, ComparatorType comparatorType, ExtTLongObjectHashMap entries, boolean cachedEntries) { + public InternalFullHistogramFacet(String name, ComparatorType comparatorType, ExtTLongObjectHashMap entries, CacheRecycler cacheRecycler) { super(name); this.comparatorType = comparatorType; this.tEntries = entries; - this.cachedEntries = cachedEntries; + this.cacheRecycler = cacheRecycler; this.entries = entries.valueCollection(); } @@ -148,15 +148,16 @@ public class InternalFullHistogramFacet extends InternalHistogramFacet { } void releaseCache() { - if (cachedEntries) { - CacheRecycler.pushLongObjectMap(tEntries); - cachedEntries = false; + if (cacheRecycler != null) { + cacheRecycler.pushLongObjectMap(tEntries); + cacheRecycler = null; tEntries = null; } } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { // we need to sort it InternalFullHistogramFacet internalFacet = (InternalFullHistogramFacet) facets.get(0); @@ -166,7 +167,7 @@ public class InternalFullHistogramFacet extends InternalHistogramFacet { return internalFacet; } - ExtTLongObjectHashMap map = CacheRecycler.popLongObjectMap(); + ExtTLongObjectHashMap map = context.cacheRecycler().popLongObjectMap(); for (Facet facet : facets) { InternalFullHistogramFacet histoFacet = (InternalFullHistogramFacet) facet; @@ -201,7 +202,7 @@ public class InternalFullHistogramFacet extends InternalHistogramFacet { ordered.add(value); } - CacheRecycler.pushLongObjectMap(map); + context.cacheRecycler().pushLongObjectMap(map); // just initialize it as already ordered facet InternalFullHistogramFacet ret = new InternalFullHistogramFacet(getName()); @@ -253,8 +254,6 @@ public class InternalFullHistogramFacet extends InternalHistogramFacet { public void readFrom(StreamInput in) throws IOException { super.readFrom(in); comparatorType = ComparatorType.fromId(in.readByte()); - - cachedEntries = false; int size = in.readVInt(); entries = new ArrayList(size); for (int i = 0; i < size; i++) { diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/ScriptHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/ScriptHistogramFacetExecutor.java index 12cad9531a6..84ee7f386f7 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/ScriptHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/ScriptHistogramFacetExecutor.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.facet.histogram; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.facet.FacetExecutor; @@ -36,6 +36,7 @@ import java.util.Map; */ public class ScriptHistogramFacetExecutor extends FacetExecutor { + final CacheRecycler cacheRecycler; final SearchScript keyScript; final SearchScript valueScript; final long interval; @@ -48,8 +49,9 @@ public class ScriptHistogramFacetExecutor extends FacetExecutor { this.valueScript = context.scriptService().search(context.lookup(), scriptLang, valueScript, params); this.interval = interval > 0 ? interval : 0; this.comparatorType = comparatorType; + this.cacheRecycler = context.cacheRecycler(); - this.entries = CacheRecycler.popLongObjectMap(); + this.entries = cacheRecycler.popLongObjectMap(); } @Override @@ -59,7 +61,7 @@ public class ScriptHistogramFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { - return new InternalFullHistogramFacet(facetName, comparatorType, entries, true); + return new InternalFullHistogramFacet(facetName, comparatorType, entries, cacheRecycler); } public static long bucket(double value, long interval) { diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/ValueHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/ValueHistogramFacetExecutor.java index d94d8d88416..08dbf9776b7 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/ValueHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/ValueHistogramFacetExecutor.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.facet.histogram; import org.apache.lucene.index.AtomicReaderContext; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; import org.elasticsearch.index.fielddata.DoubleValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; @@ -36,6 +36,7 @@ import java.io.IOException; */ public class ValueHistogramFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final IndexNumericFieldData keyIndexFieldData; private final IndexNumericFieldData valueIndexFieldData; private final HistogramFacet.ComparatorType comparatorType; @@ -48,7 +49,8 @@ public class ValueHistogramFacetExecutor extends FacetExecutor { this.keyIndexFieldData = keyIndexFieldData; this.valueIndexFieldData = valueIndexFieldData; this.interval = interval; - this.entries = CacheRecycler.popLongObjectMap(); + this.cacheRecycler = context.cacheRecycler(); + this.entries = cacheRecycler.popLongObjectMap(); } @Override @@ -58,7 +60,7 @@ public class ValueHistogramFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { - return new InternalFullHistogramFacet(facetName, comparatorType, entries, true); + return new InternalFullHistogramFacet(facetName, comparatorType, entries, cacheRecycler); } class Collector extends FacetExecutor.Collector { @@ -110,7 +112,7 @@ public class ValueHistogramFacetExecutor extends FacetExecutor { } entry.count++; valueAggregator.entry = entry; - valueAggregator.onDoc(docId, valueValues); + valueAggregator.onDoc(docId, valueValues); } public final static class ValueAggregator extends DoubleFacetAggregatorBase { diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/ValueScriptHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/ValueScriptHistogramFacetExecutor.java index 7fd9ed68f0a..47f74f83991 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/ValueScriptHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/ValueScriptHistogramFacetExecutor.java @@ -21,7 +21,7 @@ package org.elasticsearch.search.facet.histogram; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; import org.elasticsearch.index.fielddata.DoubleValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; @@ -40,6 +40,7 @@ import java.util.Map; */ public class ValueScriptHistogramFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final IndexNumericFieldData indexFieldData; private final HistogramFacet.ComparatorType comparatorType; final SearchScript valueScript; @@ -52,8 +53,9 @@ public class ValueScriptHistogramFacetExecutor extends FacetExecutor { this.indexFieldData = indexFieldData; this.interval = interval; this.valueScript = context.scriptService().search(context.lookup(), scriptLang, valueScript, params); + this.cacheRecycler = context.cacheRecycler(); - this.entries = CacheRecycler.popLongObjectMap(); + this.entries = cacheRecycler.popLongObjectMap(); } @Override @@ -63,7 +65,7 @@ public class ValueScriptHistogramFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { - return new InternalFullHistogramFacet(facetName, comparatorType, entries, true); + return new InternalFullHistogramFacet(facetName, comparatorType, entries, cacheRecycler); } public static long bucket(double value, long interval) { diff --git a/src/main/java/org/elasticsearch/search/facet/query/InternalQueryFacet.java b/src/main/java/org/elasticsearch/search/facet/query/InternalQueryFacet.java index e87edd6cdce..abea9ea68eb 100644 --- a/src/main/java/org/elasticsearch/search/facet/query/InternalQueryFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/query/InternalQueryFacet.java @@ -76,7 +76,8 @@ public class InternalQueryFacet extends InternalFacet implements QueryFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { return facets.get(0); } diff --git a/src/main/java/org/elasticsearch/search/facet/range/InternalRangeFacet.java b/src/main/java/org/elasticsearch/search/facet/range/InternalRangeFacet.java index 8667c6e5a3b..cf77b75049a 100644 --- a/src/main/java/org/elasticsearch/search/facet/range/InternalRangeFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/range/InternalRangeFacet.java @@ -84,7 +84,8 @@ public class InternalRangeFacet extends InternalFacet implements RangeFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { return facets.get(0); } diff --git a/src/main/java/org/elasticsearch/search/facet/statistical/InternalStatisticalFacet.java b/src/main/java/org/elasticsearch/search/facet/statistical/InternalStatisticalFacet.java index 540cdef05bc..8d3e118d701 100644 --- a/src/main/java/org/elasticsearch/search/facet/statistical/InternalStatisticalFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/statistical/InternalStatisticalFacet.java @@ -120,7 +120,8 @@ public class InternalStatisticalFacet extends InternalFacet implements Statistic } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { return facets.get(0); } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/TermsFacetParser.java b/src/main/java/org/elasticsearch/search/facet/terms/TermsFacetParser.java index 4c09b865545..b8471ac7a29 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/TermsFacetParser.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/TermsFacetParser.java @@ -178,7 +178,7 @@ public class TermsFacetParser extends AbstractComponent implements FacetParser { return new FieldsTermsStringFacetExecutor(facetName, mappers.toArray(new FieldMapper[mappers.size()]), size, comparatorType, allTerms, context, excluded, pattern, searchScript); } if (field == null && fieldsNames == null && script != null) { - return new ScriptTermsStringFieldFacetExecutor(size, comparatorType, context, excluded, pattern, scriptLang, script, params); + return new ScriptTermsStringFieldFacetExecutor(size, comparatorType, context, excluded, pattern, scriptLang, script, params, context.cacheRecycler()); } FieldMapper fieldMapper = context.smartNameFieldMapper(field); @@ -190,9 +190,9 @@ public class TermsFacetParser extends AbstractComponent implements FacetParser { if (indexFieldData instanceof IndexNumericFieldData) { IndexNumericFieldData indexNumericFieldData = (IndexNumericFieldData) indexFieldData; if (indexNumericFieldData.getNumericType().isFloatingPoint()) { - return new TermsDoubleFacetExecutor(indexNumericFieldData, size, comparatorType, allTerms, context, excluded, searchScript); + return new TermsDoubleFacetExecutor(indexNumericFieldData, size, comparatorType, allTerms, context, excluded, searchScript, context.cacheRecycler()); } else { - return new TermsLongFacetExecutor(indexNumericFieldData, size, comparatorType, allTerms, context, excluded, searchScript); + return new TermsLongFacetExecutor(indexNumericFieldData, size, comparatorType, allTerms, context, excluded, searchScript, context.cacheRecycler()); } } else { if (script != null || "map".equals(executionHint)) { diff --git a/src/main/java/org/elasticsearch/search/facet/terms/doubles/InternalDoubleTermsFacet.java b/src/main/java/org/elasticsearch/search/facet/terms/doubles/InternalDoubleTermsFacet.java index eb6fba5d67f..5dd1cdc633d 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/doubles/InternalDoubleTermsFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/doubles/InternalDoubleTermsFacet.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.facet.terms.doubles; import com.google.common.collect.ImmutableList; import gnu.trove.iterator.TDoubleIntIterator; import gnu.trove.map.hash.TDoubleIntHashMap; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; @@ -159,14 +158,15 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { return facets.get(0); } InternalDoubleTermsFacet first = null; - TDoubleIntHashMap aggregated = CacheRecycler.popDoubleIntMap(); + TDoubleIntHashMap aggregated = context.cacheRecycler().popDoubleIntMap(); long missing = 0; long total = 0; for (Facet facet : facets) { @@ -178,7 +178,7 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet { missing += termsFacet.getMissingCount(); total += termsFacet.getTotalCount(); for (Entry entry : termsFacet.getEntries()) { - aggregated.adjustOrPutValue(((DoubleEntry)entry).term, entry.getCount(), entry.getCount()); + aggregated.adjustOrPutValue(((DoubleEntry) entry).term, entry.getCount(), entry.getCount()); } } @@ -191,7 +191,7 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet { first.missing = missing; first.total = total; - CacheRecycler.pushDoubleIntMap(aggregated); + context.cacheRecycler().pushDoubleIntMap(aggregated); return first; } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetExecutor.java index 9464a1d3069..884150367dc 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetExecutor.java @@ -27,7 +27,7 @@ import gnu.trove.set.hash.TDoubleHashSet; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.collect.BoundedTreeSet; import org.elasticsearch.index.fielddata.DoubleValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; @@ -49,6 +49,7 @@ import java.util.Set; */ public class TermsDoubleFacetExecutor extends FacetExecutor { + private CacheRecycler cacheRecycler; private final IndexNumericFieldData indexFieldData; private final TermsFacet.ComparatorType comparatorType; private final int size; @@ -60,14 +61,15 @@ public class TermsDoubleFacetExecutor extends FacetExecutor { long total; public TermsDoubleFacetExecutor(IndexNumericFieldData indexFieldData, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, - ImmutableSet excluded, SearchScript script) { + ImmutableSet excluded, SearchScript script, CacheRecycler cacheRecycler) { this.indexFieldData = indexFieldData; this.size = size; this.comparatorType = comparatorType; this.script = script; this.excluded = excluded; + this.cacheRecycler = cacheRecycler; - this.facets = CacheRecycler.popDoubleIntMap(); + this.facets = cacheRecycler.popDoubleIntMap(); if (allTerms) { for (AtomicReaderContext readerContext : context.searcher().getTopReaderContext().leaves()) { @@ -115,7 +117,7 @@ public class TermsDoubleFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (facets.isEmpty()) { - CacheRecycler.pushDoubleIntMap(facets); + cacheRecycler.pushDoubleIntMap(facets); return new InternalDoubleTermsFacet(facetName, comparatorType, size, ImmutableList.of(), missing, total); } else { if (size < EntryPriorityQueue.LIMIT) { @@ -128,7 +130,7 @@ public class TermsDoubleFacetExecutor extends FacetExecutor { for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = (InternalDoubleTermsFacet.DoubleEntry) ordered.pop(); } - CacheRecycler.pushDoubleIntMap(facets); + cacheRecycler.pushDoubleIntMap(facets); return new InternalDoubleTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total); } else { BoundedTreeSet ordered = new BoundedTreeSet(comparatorType.comparator(), size); @@ -136,7 +138,7 @@ public class TermsDoubleFacetExecutor extends FacetExecutor { it.advance(); ordered.add(new InternalDoubleTermsFacet.DoubleEntry(it.key(), it.value())); } - CacheRecycler.pushDoubleIntMap(facets); + cacheRecycler.pushDoubleIntMap(facets); return new InternalDoubleTermsFacet(facetName, comparatorType, size, ordered, missing, total); } } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/longs/InternalLongTermsFacet.java b/src/main/java/org/elasticsearch/search/facet/terms/longs/InternalLongTermsFacet.java index 408733318dc..4bc1f2ce87f 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/longs/InternalLongTermsFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/longs/InternalLongTermsFacet.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.facet.terms.longs; import com.google.common.collect.ImmutableList; import gnu.trove.iterator.TLongIntIterator; import gnu.trove.map.hash.TLongIntHashMap; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; @@ -160,14 +159,15 @@ public class InternalLongTermsFacet extends InternalTermsFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { return facets.get(0); } InternalLongTermsFacet first = null; - TLongIntHashMap aggregated = CacheRecycler.popLongIntMap(); + TLongIntHashMap aggregated = context.cacheRecycler().popLongIntMap(); long missing = 0; long total = 0; for (Facet facet : facets) { @@ -192,7 +192,7 @@ public class InternalLongTermsFacet extends InternalTermsFacet { first.missing = missing; first.total = total; - CacheRecycler.pushLongIntMap(aggregated); + context.cacheRecycler().pushLongIntMap(aggregated); return first; } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetExecutor.java index bb5d237afd4..e78afd8126b 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetExecutor.java @@ -27,7 +27,7 @@ import gnu.trove.set.hash.TLongHashSet; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.collect.BoundedTreeSet; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.LongValues; @@ -49,6 +49,7 @@ import java.util.Set; */ public class TermsLongFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final IndexNumericFieldData indexFieldData; private final TermsFacet.ComparatorType comparatorType; private final int size; @@ -60,13 +61,14 @@ public class TermsLongFacetExecutor extends FacetExecutor { long total; public TermsLongFacetExecutor(IndexNumericFieldData indexFieldData, int size, TermsFacet.ComparatorType comparatorType, boolean allTerms, SearchContext context, - ImmutableSet excluded, SearchScript script) { + ImmutableSet excluded, SearchScript script, CacheRecycler cacheRecycler) { this.indexFieldData = indexFieldData; this.size = size; this.comparatorType = comparatorType; this.script = script; this.excluded = excluded; - this.facets = CacheRecycler.popLongIntMap(); + this.cacheRecycler = cacheRecycler; + this.facets = cacheRecycler.popLongIntMap(); if (allTerms) { for (AtomicReaderContext readerContext : context.searcher().getTopReaderContext().leaves()) { @@ -114,7 +116,7 @@ public class TermsLongFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (facets.isEmpty()) { - CacheRecycler.pushLongIntMap(facets); + cacheRecycler.pushLongIntMap(facets); return new InternalLongTermsFacet(facetName, comparatorType, size, ImmutableList.of(), missing, total); } else { if (size < EntryPriorityQueue.LIMIT) { @@ -127,7 +129,7 @@ public class TermsLongFacetExecutor extends FacetExecutor { for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = (InternalLongTermsFacet.LongEntry) ordered.pop(); } - CacheRecycler.pushLongIntMap(facets); + cacheRecycler.pushLongIntMap(facets); return new InternalLongTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total); } else { BoundedTreeSet ordered = new BoundedTreeSet(comparatorType.comparator(), size); @@ -135,7 +137,7 @@ public class TermsLongFacetExecutor extends FacetExecutor { it.advance(); ordered.add(new InternalLongTermsFacet.LongEntry(it.key(), it.value())); } - CacheRecycler.pushLongIntMap(facets); + cacheRecycler.pushLongIntMap(facets); return new InternalLongTermsFacet(facetName, comparatorType, size, ordered, missing, total); } } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/strings/InternalStringTermsFacet.java b/src/main/java/org/elasticsearch/search/facet/terms/strings/InternalStringTermsFacet.java index e98fa98fcf1..7c645472430 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/strings/InternalStringTermsFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/strings/InternalStringTermsFacet.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableList; import gnu.trove.iterator.TObjectIntIterator; import gnu.trove.map.hash.TObjectIntHashMap; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -169,14 +168,15 @@ public class InternalStringTermsFacet extends InternalTermsFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { return facets.get(0); } InternalStringTermsFacet first = null; - TObjectIntHashMap aggregated = CacheRecycler.popObjectIntMap(); + TObjectIntHashMap aggregated = context.cacheRecycler().popObjectIntMap(); long missing = 0; long total = 0; for (Facet facet : facets) { @@ -188,7 +188,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet { // the assumption is that if one of the facets is of different type, it should do the // reduction (all the facets we iterated so far most likely represent unmapped fields, if not // class cast exception will be thrown) - return termsFacet.reduce(facets); + return termsFacet.reduce(context); } if (first == null) { @@ -209,7 +209,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet { first.missing = missing; first.total = total; - CacheRecycler.pushObjectIntMap(aggregated); + context.cacheRecycler().pushObjectIntMap(aggregated); return first; } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/strings/ScriptTermsStringFieldFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/terms/strings/ScriptTermsStringFieldFacetExecutor.java index b7f5c4ece3a..8e7c1e9499b 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/strings/ScriptTermsStringFieldFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/strings/ScriptTermsStringFieldFacetExecutor.java @@ -26,7 +26,7 @@ import gnu.trove.map.hash.TObjectIntHashMap; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.collect.BoundedTreeSet; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.facet.FacetExecutor; @@ -45,6 +45,7 @@ import java.util.regex.Pattern; */ public class ScriptTermsStringFieldFacetExecutor extends FacetExecutor { + private final CacheRecycler cacheRecycler; private final InternalStringTermsFacet.ComparatorType comparatorType; private final int size; private final SearchScript script; @@ -57,16 +58,18 @@ public class ScriptTermsStringFieldFacetExecutor extends FacetExecutor { long total; public ScriptTermsStringFieldFacetExecutor(int size, InternalStringTermsFacet.ComparatorType comparatorType, SearchContext context, - ImmutableSet excluded, Pattern pattern, String scriptLang, String script, Map params) { + ImmutableSet excluded, Pattern pattern, String scriptLang, String script, Map params, + CacheRecycler cacheRecycler) { this.size = size; this.comparatorType = comparatorType; this.numberOfShards = context.numberOfShards(); this.script = context.scriptService().search(context.lookup(), scriptLang, script, params); + this.cacheRecycler = cacheRecycler; this.excluded = excluded; this.matcher = pattern != null ? pattern.matcher("") : null; - this.facets = CacheRecycler.popObjectIntMap(); + this.facets = cacheRecycler.popObjectIntMap(); } @Override @@ -77,7 +80,7 @@ public class ScriptTermsStringFieldFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (facets.isEmpty()) { - CacheRecycler.pushObjectIntMap(facets); + cacheRecycler.pushObjectIntMap(facets); return new InternalStringTermsFacet(facetName, comparatorType, size, ImmutableList.of(), missing, total); } else { if (size < EntryPriorityQueue.LIMIT) { @@ -90,7 +93,7 @@ public class ScriptTermsStringFieldFacetExecutor extends FacetExecutor { for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = ((InternalStringTermsFacet.TermEntry) ordered.pop()); } - CacheRecycler.pushObjectIntMap(facets); + cacheRecycler.pushObjectIntMap(facets); return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total); } else { BoundedTreeSet ordered = new BoundedTreeSet(comparatorType.comparator(), size); @@ -98,7 +101,7 @@ public class ScriptTermsStringFieldFacetExecutor extends FacetExecutor { it.advance(); ordered.add(new InternalStringTermsFacet.TermEntry(it.key(), it.value())); } - CacheRecycler.pushObjectIntMap(facets); + cacheRecycler.pushObjectIntMap(facets); return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, missing, total); } } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetExecutor.java index 55418d2a932..a157e114f8c 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetExecutor.java @@ -25,7 +25,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRef; import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.UnicodeUtil; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.collect.BoundedTreeSet; import org.elasticsearch.index.fielddata.BytesValues; import org.elasticsearch.index.fielddata.IndexFieldData; @@ -51,6 +51,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { private final IndexFieldData.WithOrdinals indexFieldData; + final CacheRecycler cacheRecycler; private final TermsFacet.ComparatorType comparatorType; private final int size; private final int minCount; @@ -83,6 +84,8 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { minCount = 0; } + this.cacheRecycler = context.cacheRecycler(); + this.aggregators = new ArrayList(context.searcher().getIndexReader().leaves().size()); } @@ -143,7 +146,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { for (ReaderAggregator aggregator : aggregators) { if (aggregator.counts.length > ordinalsCacheAbove) { - CacheRecycler.pushIntArray(aggregator.counts); + cacheRecycler.pushIntArray(aggregator.counts); } } @@ -186,7 +189,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { for (ReaderAggregator aggregator : aggregators) { if (aggregator.counts.length > ordinalsCacheAbove) { - CacheRecycler.pushIntArray(aggregator.counts); + cacheRecycler.pushIntArray(aggregator.counts); } } @@ -211,7 +214,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { } } values = indexFieldData.load(context).getBytesValues(); - current = new ReaderAggregator(values, ordinalsCacheAbove); + current = new ReaderAggregator(values, ordinalsCacheAbove, cacheRecycler); ordinals = values.ordinals(); } @@ -220,7 +223,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { Iter iter = ordinals.getIter(doc); int ord = iter.next(); current.onOrdinal(doc, ord); - while((ord = iter.next()) != 0) { + while ((ord = iter.next()) != 0) { current.onOrdinal(doc, ord); } } @@ -251,12 +254,12 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { int total; private final int maxOrd; - public ReaderAggregator(BytesValues.WithOrdinals values, int ordinalsCacheLimit) { + public ReaderAggregator(BytesValues.WithOrdinals values, int ordinalsCacheLimit, CacheRecycler cacheRecycler) { this.values = values; this.maxOrd = values.ordinals().getMaxOrd(); if (maxOrd > ordinalsCacheLimit) { - this.counts = CacheRecycler.popIntArray(maxOrd); + this.counts = cacheRecycler.popIntArray(maxOrd); } else { this.counts = new int[maxOrd]; } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/InternalTermsStatsDoubleFacet.java b/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/InternalTermsStatsDoubleFacet.java index 6ea8c2692c1..32d409fe1ef 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/InternalTermsStatsDoubleFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/InternalTermsStatsDoubleFacet.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.facet.termsstats.doubles; import org.apache.lucene.util.CollectionUtil; import com.google.common.collect.ImmutableList; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; @@ -170,7 +169,8 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { if (requiredSize == 0) { // we need to sort it here! @@ -183,7 +183,7 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet { return facets.get(0); } int missing = 0; - ExtTDoubleObjectHashMap map = CacheRecycler.popDoubleObjectMap(); + ExtTDoubleObjectHashMap map = context.cacheRecycler().popDoubleObjectMap(); for (Facet facet : facets) { InternalTermsStatsDoubleFacet tsFacet = (InternalTermsStatsDoubleFacet) facet; missing += tsFacet.missing; @@ -210,7 +210,7 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet { if (requiredSize == 0) { // all terms DoubleEntry[] entries1 = map.values(new DoubleEntry[map.size()]); Arrays.sort(entries1, comparatorType.comparator()); - CacheRecycler.pushDoubleObjectMap(map); + context.cacheRecycler().pushDoubleObjectMap(map); return new InternalTermsStatsDoubleFacet(getName(), comparatorType, requiredSize, Arrays.asList(entries1), missing); } else { Object[] values = map.internalValues(); @@ -223,7 +223,7 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet { } ordered.add(value); } - CacheRecycler.pushDoubleObjectMap(map); + context.cacheRecycler().pushDoubleObjectMap(map); return new InternalTermsStatsDoubleFacet(getName(), comparatorType, requiredSize, ordered, missing); } } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetExecutor.java index 6fc175cc8f4..6621819151c 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetExecutor.java @@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.trove.ExtTDoubleObjectHashMap; import org.elasticsearch.index.fielddata.DoubleValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; @@ -43,6 +43,7 @@ public class TermsStatsDoubleFacetExecutor extends FacetExecutor { private final TermsStatsFacet.ComparatorType comparatorType; + final CacheRecycler cacheRecycler; final IndexNumericFieldData keyIndexFieldData; final IndexNumericFieldData valueIndexFieldData; final SearchScript script; @@ -59,8 +60,9 @@ public class TermsStatsDoubleFacetExecutor extends FacetExecutor { this.keyIndexFieldData = keyIndexFieldData; this.valueIndexFieldData = valueIndexFieldData; this.script = script; + this.cacheRecycler = context.cacheRecycler(); - this.entries = CacheRecycler.popDoubleObjectMap(); + this.entries = cacheRecycler.popDoubleObjectMap(); } @Override @@ -90,7 +92,7 @@ public class TermsStatsDoubleFacetExecutor extends FacetExecutor { ordered.add(value); } - CacheRecycler.pushDoubleObjectMap(entries); + cacheRecycler.pushDoubleObjectMap(entries); return new InternalTermsStatsDoubleFacet(facetName, comparatorType, size, ordered, missing); } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/longs/InternalTermsStatsLongFacet.java b/src/main/java/org/elasticsearch/search/facet/termsstats/longs/InternalTermsStatsLongFacet.java index 7ccc63da9c3..71fd194e835 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/longs/InternalTermsStatsLongFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/longs/InternalTermsStatsLongFacet.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.facet.termsstats.longs; import com.google.common.collect.ImmutableList; import org.apache.lucene.util.CollectionUtil; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.HashedBytesArray; @@ -169,7 +168,8 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { if (requiredSize == 0) { // we need to sort it here! @@ -182,7 +182,7 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet { return facets.get(0); } int missing = 0; - ExtTLongObjectHashMap map = CacheRecycler.popLongObjectMap(); + ExtTLongObjectHashMap map = context.cacheRecycler().popLongObjectMap(); for (Facet facet : facets) { InternalTermsStatsLongFacet tsFacet = (InternalTermsStatsLongFacet) facet; missing += tsFacet.missing; @@ -209,7 +209,7 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet { if (requiredSize == 0) { // all terms LongEntry[] entries1 = map.values(new LongEntry[map.size()]); Arrays.sort(entries1, comparatorType.comparator()); - CacheRecycler.pushLongObjectMap(map); + context.cacheRecycler().pushLongObjectMap(map); return new InternalTermsStatsLongFacet(getName(), comparatorType, requiredSize, Arrays.asList(entries1), missing); } else { Object[] values = map.internalValues(); @@ -222,7 +222,7 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet { } ordered.add(value); } - CacheRecycler.pushLongObjectMap(map); + context.cacheRecycler().pushLongObjectMap(map); return new InternalTermsStatsLongFacet(getName(), comparatorType, requiredSize, ordered, missing); } } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetExecutor.java index 76804651884..c3ac6274a66 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetExecutor.java @@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.trove.ExtTLongObjectHashMap; import org.elasticsearch.index.fielddata.DoubleValues; import org.elasticsearch.index.fielddata.IndexNumericFieldData; @@ -44,6 +44,7 @@ import java.util.List; public class TermsStatsLongFacetExecutor extends FacetExecutor { private final TermsStatsFacet.ComparatorType comparatorType; + final CacheRecycler cacheRecycler; final IndexNumericFieldData keyIndexFieldData; final IndexNumericFieldData valueIndexFieldData; final SearchScript script; @@ -60,8 +61,9 @@ public class TermsStatsLongFacetExecutor extends FacetExecutor { this.keyIndexFieldData = keyIndexFieldData; this.valueIndexFieldData = valueIndexFieldData; this.script = script; + this.cacheRecycler = context.cacheRecycler(); - this.entries = CacheRecycler.popLongObjectMap(); + this.entries = cacheRecycler.popLongObjectMap(); } @Override @@ -92,7 +94,7 @@ public class TermsStatsLongFacetExecutor extends FacetExecutor { } ordered.add(value); } - CacheRecycler.pushLongObjectMap(entries); + cacheRecycler.pushLongObjectMap(entries); return new InternalTermsStatsLongFacet(facetName, comparatorType, size, ordered, missing); } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/strings/InternalTermsStatsStringFacet.java b/src/main/java/org/elasticsearch/search/facet/termsstats/strings/InternalTermsStatsStringFacet.java index 65d66f418b7..a9d1959c409 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/strings/InternalTermsStatsStringFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/strings/InternalTermsStatsStringFacet.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.facet.termsstats.strings; import com.google.common.collect.ImmutableList; import org.apache.lucene.util.CollectionUtil; -import org.elasticsearch.common.CacheRecycler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -174,7 +173,8 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet { } @Override - public Facet reduce(List facets) { + public Facet reduce(ReduceContext context) { + List facets = context.facets(); if (facets.size() == 1) { if (requiredSize == 0) { // we need to sort it here! @@ -187,7 +187,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet { return facets.get(0); } int missing = 0; - ExtTHashMap map = CacheRecycler.popHashMap(); + ExtTHashMap map = context.cacheRecycler().popHashMap(); for (Facet facet : facets) { InternalTermsStatsStringFacet tsFacet = (InternalTermsStatsStringFacet) facet; missing += tsFacet.missing; @@ -214,7 +214,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet { if (requiredSize == 0) { // all terms StringEntry[] entries1 = map.values().toArray(new StringEntry[map.size()]); Arrays.sort(entries1, comparatorType.comparator()); - CacheRecycler.pushHashMap(map); + context.cacheRecycler().pushHashMap(map); return new InternalTermsStatsStringFacet(getName(), comparatorType, requiredSize, Arrays.asList(entries1), missing); } else { Object[] values = map.internalValues(); @@ -227,7 +227,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet { } ordered.add(value); } - CacheRecycler.pushHashMap(map); + context.cacheRecycler().pushHashMap(map); return new InternalTermsStatsStringFacet(getName(), comparatorType, requiredSize, ordered, missing); } } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetExecutor.java index faf3b262f01..89454ece27f 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetExecutor.java @@ -24,7 +24,7 @@ import com.google.common.collect.Lists; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.CacheRecycler; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.lucene.HashedBytesRef; import org.elasticsearch.common.trove.ExtTHashMap; import org.elasticsearch.index.fielddata.BytesValues; @@ -47,6 +47,7 @@ import java.util.List; public class TermsStatsStringFacetExecutor extends FacetExecutor { private final TermsStatsFacet.ComparatorType comparatorType; + final CacheRecycler cacheRecycler; final IndexFieldData keyIndexFieldData; final IndexNumericFieldData valueIndexFieldData; final SearchScript script; @@ -62,7 +63,9 @@ public class TermsStatsStringFacetExecutor extends FacetExecutor { this.script = valueScript; this.size = size; this.comparatorType = comparatorType; - this.entries = CacheRecycler.popHashMap(); + this.cacheRecycler = context.cacheRecycler(); + + this.entries = cacheRecycler.popHashMap(); } @Override @@ -92,7 +95,7 @@ public class TermsStatsStringFacetExecutor extends FacetExecutor { ordered.add(value); } - CacheRecycler.pushHashMap(entries); // fine to push here, we are done with it + cacheRecycler.pushHashMap(entries); // fine to push here, we are done with it return new InternalTermsStatsStringFacet(facetName, comparatorType, size, ordered, missing); } diff --git a/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/src/main/java/org/elasticsearch/search/internal/SearchContext.java index fa0fee30999..ed3ed08c903 100644 --- a/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -26,6 +26,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.Sort; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.lucene.search.AndFilter; @@ -107,6 +108,8 @@ public class SearchContext implements Releasable { private final ScriptService scriptService; + private final CacheRecycler cacheRecycler; + private final IndexShard indexShard; private final IndexService indexService; @@ -184,13 +187,15 @@ public class SearchContext implements Releasable { public SearchContext(long id, ShardSearchRequest request, SearchShardTarget shardTarget, - Engine.Searcher engineSearcher, IndexService indexService, IndexShard indexShard, ScriptService scriptService) { + Engine.Searcher engineSearcher, IndexService indexService, IndexShard indexShard, + ScriptService scriptService, CacheRecycler cacheRecycler) { this.id = id; this.request = request; this.searchType = request.searchType(); this.shardTarget = shardTarget; this.engineSearcher = engineSearcher; this.scriptService = scriptService; + this.cacheRecycler = cacheRecycler; this.dfsResult = new DfsSearchResult(id, shardTarget); this.queryResult = new QuerySearchResult(id, shardTarget); this.fetchResult = new FetchSearchResult(id, shardTarget); @@ -393,6 +398,10 @@ public class SearchContext implements Releasable { return scriptService; } + public CacheRecycler cacheRecycler() { + return cacheRecycler; + } + public FilterCache filterCache() { return indexService.cache().filter(); } diff --git a/src/test/java/org/elasticsearch/test/unit/index/aliases/IndexAliasesServiceTests.java b/src/test/java/org/elasticsearch/test/unit/index/aliases/IndexAliasesServiceTests.java index 437a5082010..f349449d8f6 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/aliases/IndexAliasesServiceTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/aliases/IndexAliasesServiceTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.unit.index.aliases; +import org.elasticsearch.cache.recycler.CacheRecyclerModule; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.compress.CompressedString; import org.elasticsearch.common.inject.AbstractModule; @@ -65,6 +66,7 @@ public class IndexAliasesServiceTests { public static IndexQueryParserService newIndexQueryParserService() { Injector injector = new ModulesBuilder().add( new IndicesQueriesModule(), + new CacheRecyclerModule(ImmutableSettings.Builder.EMPTY_SETTINGS), new CodecModule(ImmutableSettings.Builder.EMPTY_SETTINGS), new IndexSettingsModule(new Index("test"), ImmutableSettings.Builder.EMPTY_SETTINGS), new IndexNameModule(new Index("test")), diff --git a/src/test/java/org/elasticsearch/test/unit/index/percolator/PercolatorExecutorTests.java b/src/test/java/org/elasticsearch/test/unit/index/percolator/PercolatorExecutorTests.java index 18c5bf26f77..c9de5e6092a 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/percolator/PercolatorExecutorTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/percolator/PercolatorExecutorTests.java @@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import org.elasticsearch.cache.recycler.CacheRecyclerModule; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.AbstractModule; @@ -81,6 +82,7 @@ public class PercolatorExecutorTests { .build(); Index index = new Index("test"); injector = new ModulesBuilder().add( + new CacheRecyclerModule(settings), new IndexSettingsModule(index, settings), new CodecModule(settings), new SettingsModule(settings), diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java b/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java index 15764c19e50..38cbaa3e087 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java @@ -31,6 +31,7 @@ import org.apache.lucene.search.spans.*; import org.apache.lucene.spatial.prefix.IntersectsPrefixTreeFilter; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.NumericUtils; +import org.elasticsearch.cache.recycler.CacheRecyclerModule; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -102,6 +103,7 @@ public class SimpleIndexQueryParserTests { .build(); Index index = new Index("test"); injector = new ModulesBuilder().add( + new CacheRecyclerModule(settings), new CodecModule(settings), new SettingsModule(settings), new ThreadPoolModule(settings), diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/guice/IndexQueryParserModuleTests.java b/src/test/java/org/elasticsearch/test/unit/index/query/guice/IndexQueryParserModuleTests.java index ab0453c4776..3ed71637616 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/query/guice/IndexQueryParserModuleTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/query/guice/IndexQueryParserModuleTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.unit.index.query.guice; +import org.elasticsearch.cache.recycler.CacheRecyclerModule; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Injector; @@ -64,6 +65,7 @@ public class IndexQueryParserModuleTests { Index index = new Index("test"); Injector injector = new ModulesBuilder().add( new SettingsModule(settings), + new CacheRecyclerModule(settings), new CodecModule(settings), new ThreadPoolModule(settings), new IndicesQueriesModule(), diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/plugin/IndexQueryParserPlugin2Tests.java b/src/test/java/org/elasticsearch/test/unit/index/query/plugin/IndexQueryParserPlugin2Tests.java index fc63b2f943d..1b12976dbc0 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/query/plugin/IndexQueryParserPlugin2Tests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/query/plugin/IndexQueryParserPlugin2Tests.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.unit.index.query.plugin; +import org.elasticsearch.cache.recycler.CacheRecyclerModule; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Injector; @@ -62,6 +63,7 @@ public class IndexQueryParserPlugin2Tests { Index index = new Index("test"); Injector injector = new ModulesBuilder().add( new CodecModule(settings), + new CacheRecyclerModule(settings), new SettingsModule(settings), new ThreadPoolModule(settings), new IndicesQueriesModule(), diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/plugin/IndexQueryParserPluginTests.java b/src/test/java/org/elasticsearch/test/unit/index/query/plugin/IndexQueryParserPluginTests.java index 3540bd3a228..e0060f3dd29 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/query/plugin/IndexQueryParserPluginTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/query/plugin/IndexQueryParserPluginTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.unit.index.query.plugin; +import org.elasticsearch.cache.recycler.CacheRecyclerModule; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Injector; @@ -71,6 +72,7 @@ public class IndexQueryParserPluginTests { Index index = new Index("test"); Injector injector = new ModulesBuilder().add( new SettingsModule(settings), + new CacheRecyclerModule(settings), new ThreadPoolModule(settings), new IndicesQueriesModule(), new ScriptModule(settings),