Create ShardSuggestService/Metrics manually outside of guice

This ShardSuggestService is a simple metrics counter and doesn't need
to be injected. It just makes IndexShard ctor bigger for no reason.
This commit is contained in:
Simon Willnauer 2015-06-11 17:32:29 +02:00
parent a216062d88
commit fab27f1bb0
5 changed files with 14 additions and 25 deletions

View File

@ -39,7 +39,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.suggest.stats.ShardSuggestService;
import org.elasticsearch.index.suggest.stats.ShardSuggestMetric;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.SuggestPhase;
@ -130,8 +130,8 @@ public class TransportSuggestAction extends TransportBroadcastAction<SuggestRequ
protected ShardSuggestResponse shardOperation(ShardSuggestRequest request) {
IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
IndexShard indexShard = indexService.shardSafe(request.shardId().id());
ShardSuggestService shardSuggestService = indexShard.shardSuggestService();
shardSuggestService.preSuggest();
ShardSuggestMetric suggestMetric = indexShard.getSuggestMetric();
suggestMetric.preSuggest();
long startTime = System.nanoTime();
XContentParser parser = null;
try (Engine.Searcher searcher = indexShard.acquireSearcher("suggest")) {
@ -153,7 +153,7 @@ public class TransportSuggestAction extends TransportBroadcastAction<SuggestRequ
if (parser != null) {
parser.close();
}
shardSuggestService.postSuggest(System.nanoTime() - startTime);
suggestMetric.postSuggest(System.nanoTime() - startTime);
}
}
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.index.shard;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.index.*;
import org.apache.lucene.index.CheckIndex;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.ThreadInterruptedException;
@ -88,7 +88,7 @@ import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.store.Store.MetadataSnapshot;
import org.elasticsearch.index.store.StoreFileMetaData;
import org.elasticsearch.index.store.StoreStats;
import org.elasticsearch.index.suggest.stats.ShardSuggestService;
import org.elasticsearch.index.suggest.stats.ShardSuggestMetric;
import org.elasticsearch.index.suggest.stats.SuggestStats;
import org.elasticsearch.index.termvectors.ShardTermVectorsService;
import org.elasticsearch.index.translog.Translog;
@ -142,7 +142,7 @@ public class IndexShard extends AbstractIndexShardComponent {
private final ShardTermVectorsService termVectorsService;
private final IndexFieldDataService indexFieldDataService;
private final IndexService indexService;
private final ShardSuggestService shardSuggestService;
private final ShardSuggestMetric shardSuggestMetric = new ShardSuggestMetric();
private final ShardBitsetFilterCache shardBitsetFilterCache;
private final DiscoveryNode localNode;
@ -194,7 +194,7 @@ public class IndexShard extends AbstractIndexShardComponent {
public IndexShard(ShardId shardId, IndexSettingsService indexSettingsService, IndicesLifecycle indicesLifecycle, Store store,
ThreadPool threadPool, MapperService mapperService, IndexQueryParserService queryParserService, IndexCache indexCache, IndexAliasesService indexAliasesService, ShardIndexingService indexingService, ShardGetService getService, ShardSearchService searchService, ShardIndexWarmerService shardWarmerService,
ShardFilterCache shardFilterCache, ShardFieldData shardFieldData, PercolatorQueriesRegistry percolatorQueriesRegistry, ShardPercolateService shardPercolateService, CodecService codecService,
ShardTermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService, IndexService indexService, ShardSuggestService shardSuggestService,
ShardTermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService, IndexService indexService,
ShardQueryCache shardQueryCache, ShardBitsetFilterCache shardBitsetFilterCache,
@Nullable IndicesWarmer warmer, SnapshotDeletionPolicy deletionPolicy, SimilarityService similarityService, EngineFactory factory,
ClusterService clusterService, NodeEnvironment nodeEnv, ShardPath path, BigArrays bigArrays) {
@ -227,7 +227,6 @@ public class IndexShard extends AbstractIndexShardComponent {
this.shardPercolateService = shardPercolateService;
this.indexFieldDataService = indexFieldDataService;
this.indexService = indexService;
this.shardSuggestService = shardSuggestService;
this.shardBitsetFilterCache = shardBitsetFilterCache;
assert clusterService.localNode() != null : "Local node is null lifecycle state is: " + clusterService.lifecycleState();
this.localNode = clusterService.localNode();
@ -273,8 +272,8 @@ public class IndexShard extends AbstractIndexShardComponent {
return termVectorsService;
}
public ShardSuggestService shardSuggestService() {
return shardSuggestService;
public ShardSuggestMetric getSuggestMetric() {
return shardSuggestMetric;
}
public ShardBitsetFilterCache shardBitsetFilterCache() {
@ -646,7 +645,7 @@ public class IndexShard extends AbstractIndexShardComponent {
}
public SuggestStats suggestStats() {
return shardSuggestService.stats();
return shardSuggestMetric.stats();
}
public CompletionStats completionStats(String... fields) {

View File

@ -38,7 +38,6 @@ import org.elasticsearch.index.percolator.stats.ShardPercolateService;
import org.elasticsearch.index.search.slowlog.ShardSlowLogSearchService;
import org.elasticsearch.index.search.stats.ShardSearchService;
import org.elasticsearch.index.snapshots.IndexShardSnapshotAndRestoreService;
import org.elasticsearch.index.suggest.stats.ShardSuggestService;
import org.elasticsearch.index.termvectors.ShardTermVectorsService;
import org.elasticsearch.index.translog.TranslogService;
import org.elasticsearch.index.warmer.ShardIndexWarmerService;
@ -103,7 +102,6 @@ public class IndexShardModule extends AbstractModule {
bind(ShardPercolateService.class).asEagerSingleton();
bind(ShardTermVectorsService.class).asEagerSingleton();
bind(IndexShardSnapshotAndRestoreService.class).asEagerSingleton();
bind(ShardSuggestService.class).asEagerSingleton();
}

View File

@ -48,7 +48,6 @@ import org.elasticsearch.index.search.stats.ShardSearchService;
import org.elasticsearch.index.settings.IndexSettingsService;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.suggest.stats.ShardSuggestService;
import org.elasticsearch.index.termvectors.ShardTermVectorsService;
import org.elasticsearch.index.warmer.ShardIndexWarmerService;
import org.elasticsearch.indices.IndicesLifecycle;
@ -76,7 +75,7 @@ public final class ShadowIndexShard extends IndexShard {
ShardFieldData shardFieldData, PercolatorQueriesRegistry percolatorQueriesRegistry,
ShardPercolateService shardPercolateService, CodecService codecService,
ShardTermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService,
IndexService indexService, ShardSuggestService shardSuggestService, ShardQueryCache shardQueryCache,
IndexService indexService, ShardQueryCache shardQueryCache,
ShardBitsetFilterCache shardBitsetFilterCache, @Nullable IndicesWarmer warmer,
SnapshotDeletionPolicy deletionPolicy, SimilarityService similarityService,
EngineFactory factory, ClusterService clusterService,
@ -85,7 +84,7 @@ public final class ShadowIndexShard extends IndexShard {
threadPool, mapperService, queryParserService, indexCache, indexAliasesService,
indexingService, getService, searchService, shardWarmerService, shardFilterCache,
shardFieldData, percolatorQueriesRegistry, shardPercolateService, codecService,
termVectorsService, indexFieldDataService, indexService, shardSuggestService,
termVectorsService, indexFieldDataService, indexService,
shardQueryCache, shardBitsetFilterCache, warmer, deletionPolicy, similarityService,
factory, clusterService, nodeEnv, path, bigArrays);
}

View File

@ -32,16 +32,10 @@ import java.util.concurrent.TimeUnit;
/**
*
*/
public class ShardSuggestService extends AbstractIndexShardComponent {
public final class ShardSuggestMetric {
private final MeanMetric suggestMetric = new MeanMetric();
private final CounterMetric currentMetric = new CounterMetric();
@Inject
public ShardSuggestService(ShardId shardId, @IndexSettings Settings indexSettings) {
super(shardId, indexSettings);
}
/**
* Called before suggest
*/
@ -64,5 +58,4 @@ public class ShardSuggestService extends AbstractIndexShardComponent {
public SuggestStats stats() {
return new SuggestStats(suggestMetric.count(), TimeUnit.NANOSECONDS.toMillis(suggestMetric.sum()), currentMetric.count());
}
}