Fold ShardGetService creation away from Guice into IndexShard

it's always acccessed via IndexShard and has crazy circular dependencies or
rather had. It just makes IndexShard ctor bigger for no reason.
This commit is contained in:
Simon Willnauer 2015-06-11 17:46:50 +02:00
parent a216062d88
commit 9e19090b2b
4 changed files with 16 additions and 34 deletions

View File

@ -64,41 +64,26 @@ import static com.google.common.collect.Maps.newHashMapWithExpectedSize;
/** /**
*/ */
public class ShardGetService extends AbstractIndexShardComponent { public final class ShardGetService extends AbstractIndexShardComponent {
private final ScriptService scriptService;
private final MapperService mapperService; private final MapperService mapperService;
private final IndexFieldDataService fieldDataService;
private IndexShard indexShard;
private final MeanMetric existsMetric = new MeanMetric(); private final MeanMetric existsMetric = new MeanMetric();
private final MeanMetric missingMetric = new MeanMetric(); private final MeanMetric missingMetric = new MeanMetric();
private final CounterMetric currentMetric = new CounterMetric(); private final CounterMetric currentMetric = new CounterMetric();
private final IndexShard indexShard;
@Inject public ShardGetService(IndexShard indexShard,
public ShardGetService(ShardId shardId, @IndexSettings Settings indexSettings, ScriptService scriptService, MapperService mapperService) {
MapperService mapperService, IndexFieldDataService fieldDataService) { super(indexShard.shardId(), indexShard.indexSettings());
super(shardId, indexSettings);
this.scriptService = scriptService;
this.mapperService = mapperService; this.mapperService = mapperService;
this.fieldDataService = fieldDataService; this.indexShard = indexShard;
} }
public GetStats stats() { public GetStats stats() {
return new GetStats(existsMetric.count(), TimeUnit.NANOSECONDS.toMillis(existsMetric.sum()), missingMetric.count(), TimeUnit.NANOSECONDS.toMillis(missingMetric.sum()), currentMetric.count()); return new GetStats(existsMetric.count(), TimeUnit.NANOSECONDS.toMillis(existsMetric.sum()), missingMetric.count(), TimeUnit.NANOSECONDS.toMillis(missingMetric.sum()), currentMetric.count());
} }
// sadly, to overcome cyclic dep, we need to do this and inject it ourselves...
public ShardGetService setIndexShard(IndexShard indexShard) {
this.indexShard = indexShard;
return this;
}
public GetResult get(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext, boolean ignoreErrorsOnGeneratedFields) public GetResult get(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext, boolean ignoreErrorsOnGeneratedFields) {
{
currentMetric.inc(); currentMetric.inc();
try { try {
long now = System.nanoTime(); long now = System.nanoTime();
@ -151,7 +136,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
/** /**
* decides what needs to be done based on the request input and always returns a valid non-null FetchSourceContext * decides what needs to be done based on the request input and always returns a valid non-null FetchSourceContext
*/ */
protected FetchSourceContext normalizeFetchSourceContent(@Nullable FetchSourceContext context, @Nullable String[] gFields) { private FetchSourceContext normalizeFetchSourceContent(@Nullable FetchSourceContext context, @Nullable String[] gFields) {
if (context != null) { if (context != null) {
return context; return context;
} }
@ -166,7 +151,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
return FetchSourceContext.DO_NOT_FETCH_SOURCE; return FetchSourceContext.DO_NOT_FETCH_SOURCE;
} }
public GetResult innerGet(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext, boolean ignoreErrorsOnGeneratedFields) { private GetResult innerGet(String type, String id, String[] gFields, boolean realtime, long version, VersionType versionType, FetchSourceContext fetchSourceContext, boolean ignoreErrorsOnGeneratedFields) {
fetchSourceContext = normalizeFetchSourceContent(fetchSourceContext, gFields); fetchSourceContext = normalizeFetchSourceContent(fetchSourceContext, gFields);
boolean loadSource = (gFields != null && gFields.length > 0) || fetchSourceContext.fetchSource(); boolean loadSource = (gFields != null && gFields.length > 0) || fetchSourceContext.fetchSource();
@ -238,7 +223,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
value = source.source.length(); value = source.source.length();
} else { } else {
if (searchLookup == null) { if (searchLookup == null) {
searchLookup = new SearchLookup(mapperService, fieldDataService, new String[]{type}); searchLookup = new SearchLookup(mapperService, null, new String[]{type});
searchLookup.source().setSource(source.source); searchLookup.source().setSource(source.source);
} }
@ -370,7 +355,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
} }
} else if (!fieldMapper.fieldType().stored() && !fieldMapper.isGenerated()) { } else if (!fieldMapper.fieldType().stored() && !fieldMapper.isGenerated()) {
if (searchLookup == null) { if (searchLookup == null) {
searchLookup = new SearchLookup(mapperService, fieldDataService, new String[]{type}); searchLookup = new SearchLookup(mapperService, null, new String[]{type});
LeafSearchLookup leafSearchLookup = searchLookup.getLeafSearchLookup(docIdAndVersion.context); LeafSearchLookup leafSearchLookup = searchLookup.getLeafSearchLookup(docIdAndVersion.context);
searchLookup.source().setSource(source); searchLookup.source().setSource(source);
leafSearchLookup.setDocument(docIdAndVersion.docId); leafSearchLookup.setDocument(docIdAndVersion.docId);

View File

@ -22,7 +22,7 @@ package org.elasticsearch.index.shard;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.apache.lucene.codecs.PostingsFormat; 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.store.AlreadyClosedException;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.ThreadInterruptedException; import org.apache.lucene.util.ThreadInterruptedException;
@ -192,7 +192,7 @@ public class IndexShard extends AbstractIndexShardComponent {
@Inject @Inject
public IndexShard(ShardId shardId, IndexSettingsService indexSettingsService, IndicesLifecycle indicesLifecycle, Store store, 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, ThreadPool threadPool, MapperService mapperService, IndexQueryParserService queryParserService, IndexCache indexCache, IndexAliasesService indexAliasesService, ShardIndexingService indexingService, ShardSearchService searchService, ShardIndexWarmerService shardWarmerService,
ShardFilterCache shardFilterCache, ShardFieldData shardFieldData, PercolatorQueriesRegistry percolatorQueriesRegistry, ShardPercolateService shardPercolateService, CodecService codecService, ShardFilterCache shardFilterCache, ShardFieldData shardFieldData, PercolatorQueriesRegistry percolatorQueriesRegistry, ShardPercolateService shardPercolateService, CodecService codecService,
ShardTermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService, IndexService indexService, ShardSuggestService shardSuggestService, ShardTermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService, IndexService indexService, ShardSuggestService shardSuggestService,
ShardQueryCache shardQueryCache, ShardBitsetFilterCache shardBitsetFilterCache, ShardQueryCache shardQueryCache, ShardBitsetFilterCache shardBitsetFilterCache,
@ -216,7 +216,7 @@ public class IndexShard extends AbstractIndexShardComponent {
this.indexCache = indexCache; this.indexCache = indexCache;
this.indexAliasesService = indexAliasesService; this.indexAliasesService = indexAliasesService;
this.indexingService = indexingService; this.indexingService = indexingService;
this.getService = getService.setIndexShard(this); this.getService = new ShardGetService(this, mapperService);
this.termVectorsService = termVectorsService.setIndexShard(this); this.termVectorsService = termVectorsService.setIndexShard(this);
this.searchService = searchService; this.searchService = searchService;
this.shardWarmerService = shardWarmerService; this.shardWarmerService = shardWarmerService;

View File

@ -30,7 +30,6 @@ import org.elasticsearch.index.engine.InternalEngineFactory;
import org.elasticsearch.index.fielddata.ShardFieldData; import org.elasticsearch.index.fielddata.ShardFieldData;
import org.elasticsearch.index.gateway.IndexShardGateway; import org.elasticsearch.index.gateway.IndexShardGateway;
import org.elasticsearch.index.gateway.IndexShardGatewayService; import org.elasticsearch.index.gateway.IndexShardGatewayService;
import org.elasticsearch.index.get.ShardGetService;
import org.elasticsearch.index.indexing.ShardIndexingService; import org.elasticsearch.index.indexing.ShardIndexingService;
import org.elasticsearch.index.indexing.slowlog.ShardSlowLogIndexingService; import org.elasticsearch.index.indexing.slowlog.ShardSlowLogIndexingService;
import org.elasticsearch.index.percolator.PercolatorQueriesRegistry; import org.elasticsearch.index.percolator.PercolatorQueriesRegistry;
@ -92,7 +91,6 @@ public class IndexShardModule extends AbstractModule {
bind(ShardSlowLogIndexingService.class).asEagerSingleton(); bind(ShardSlowLogIndexingService.class).asEagerSingleton();
bind(ShardSearchService.class).asEagerSingleton(); bind(ShardSearchService.class).asEagerSingleton();
bind(ShardSlowLogSearchService.class).asEagerSingleton(); bind(ShardSlowLogSearchService.class).asEagerSingleton();
bind(ShardGetService.class).asEagerSingleton();
bind(ShardFilterCache.class).toInstance(shardFilterCache); bind(ShardFilterCache.class).toInstance(shardFilterCache);
bind(ShardQueryCache.class).asEagerSingleton(); bind(ShardQueryCache.class).asEagerSingleton();
bind(ShardBitsetFilterCache.class).asEagerSingleton(); bind(ShardBitsetFilterCache.class).asEagerSingleton();

View File

@ -37,7 +37,6 @@ import org.elasticsearch.index.engine.EngineConfig;
import org.elasticsearch.index.engine.EngineFactory; import org.elasticsearch.index.engine.EngineFactory;
import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.fielddata.IndexFieldDataService;
import org.elasticsearch.index.fielddata.ShardFieldData; import org.elasticsearch.index.fielddata.ShardFieldData;
import org.elasticsearch.index.get.ShardGetService;
import org.elasticsearch.index.indexing.ShardIndexingService; import org.elasticsearch.index.indexing.ShardIndexingService;
import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.merge.MergeStats; import org.elasticsearch.index.merge.MergeStats;
@ -71,7 +70,7 @@ public final class ShadowIndexShard extends IndexShard {
ThreadPool threadPool, MapperService mapperService, ThreadPool threadPool, MapperService mapperService,
IndexQueryParserService queryParserService, IndexCache indexCache, IndexQueryParserService queryParserService, IndexCache indexCache,
IndexAliasesService indexAliasesService, ShardIndexingService indexingService, IndexAliasesService indexAliasesService, ShardIndexingService indexingService,
ShardGetService getService, ShardSearchService searchService, ShardSearchService searchService,
ShardIndexWarmerService shardWarmerService, ShardFilterCache shardFilterCache, ShardIndexWarmerService shardWarmerService, ShardFilterCache shardFilterCache,
ShardFieldData shardFieldData, PercolatorQueriesRegistry percolatorQueriesRegistry, ShardFieldData shardFieldData, PercolatorQueriesRegistry percolatorQueriesRegistry,
ShardPercolateService shardPercolateService, CodecService codecService, ShardPercolateService shardPercolateService, CodecService codecService,
@ -83,7 +82,7 @@ public final class ShadowIndexShard extends IndexShard {
NodeEnvironment nodeEnv, ShardPath path, BigArrays bigArrays) throws IOException { NodeEnvironment nodeEnv, ShardPath path, BigArrays bigArrays) throws IOException {
super(shardId, indexSettingsService, indicesLifecycle, store, super(shardId, indexSettingsService, indicesLifecycle, store,
threadPool, mapperService, queryParserService, indexCache, indexAliasesService, threadPool, mapperService, queryParserService, indexCache, indexAliasesService,
indexingService, getService, searchService, shardWarmerService, shardFilterCache, indexingService, searchService, shardWarmerService, shardFilterCache,
shardFieldData, percolatorQueriesRegistry, shardPercolateService, codecService, shardFieldData, percolatorQueriesRegistry, shardPercolateService, codecService,
termVectorsService, indexFieldDataService, indexService, shardSuggestService, termVectorsService, indexFieldDataService, indexService, shardSuggestService,
shardQueryCache, shardBitsetFilterCache, warmer, deletionPolicy, similarityService, shardQueryCache, shardBitsetFilterCache, warmer, deletionPolicy, similarityService,