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:
parent
a216062d88
commit
9e19090b2b
|
@ -64,41 +64,26 @@ import static com.google.common.collect.Maps.newHashMapWithExpectedSize;
|
|||
|
||||
/**
|
||||
*/
|
||||
public class ShardGetService extends AbstractIndexShardComponent {
|
||||
|
||||
private final ScriptService scriptService;
|
||||
|
||||
public final class ShardGetService extends AbstractIndexShardComponent {
|
||||
private final MapperService mapperService;
|
||||
|
||||
private final IndexFieldDataService fieldDataService;
|
||||
|
||||
private IndexShard indexShard;
|
||||
|
||||
private final MeanMetric existsMetric = new MeanMetric();
|
||||
private final MeanMetric missingMetric = new MeanMetric();
|
||||
private final CounterMetric currentMetric = new CounterMetric();
|
||||
private final IndexShard indexShard;
|
||||
|
||||
@Inject
|
||||
public ShardGetService(ShardId shardId, @IndexSettings Settings indexSettings, ScriptService scriptService,
|
||||
MapperService mapperService, IndexFieldDataService fieldDataService) {
|
||||
super(shardId, indexSettings);
|
||||
this.scriptService = scriptService;
|
||||
public ShardGetService(IndexShard indexShard,
|
||||
MapperService mapperService) {
|
||||
super(indexShard.shardId(), indexShard.indexSettings());
|
||||
this.mapperService = mapperService;
|
||||
this.fieldDataService = fieldDataService;
|
||||
this.indexShard = indexShard;
|
||||
}
|
||||
|
||||
public GetStats stats() {
|
||||
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();
|
||||
try {
|
||||
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
|
||||
*/
|
||||
protected FetchSourceContext normalizeFetchSourceContent(@Nullable FetchSourceContext context, @Nullable String[] gFields) {
|
||||
private FetchSourceContext normalizeFetchSourceContent(@Nullable FetchSourceContext context, @Nullable String[] gFields) {
|
||||
if (context != null) {
|
||||
return context;
|
||||
}
|
||||
|
@ -166,7 +151,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
|
|||
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);
|
||||
|
||||
boolean loadSource = (gFields != null && gFields.length > 0) || fetchSourceContext.fetchSource();
|
||||
|
@ -238,7 +223,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
|
|||
value = source.source.length();
|
||||
} else {
|
||||
if (searchLookup == null) {
|
||||
searchLookup = new SearchLookup(mapperService, fieldDataService, new String[]{type});
|
||||
searchLookup = new SearchLookup(mapperService, null, new String[]{type});
|
||||
searchLookup.source().setSource(source.source);
|
||||
}
|
||||
|
||||
|
@ -370,7 +355,7 @@ public class ShardGetService extends AbstractIndexShardComponent {
|
|||
}
|
||||
} else if (!fieldMapper.fieldType().stored() && !fieldMapper.isGenerated()) {
|
||||
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);
|
||||
searchLookup.source().setSource(source);
|
||||
leafSearchLookup.setDocument(docIdAndVersion.docId);
|
||||
|
|
|
@ -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;
|
||||
|
@ -192,7 +192,7 @@ public class IndexShard extends AbstractIndexShardComponent {
|
|||
|
||||
@Inject
|
||||
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,
|
||||
ShardTermVectorsService termVectorsService, IndexFieldDataService indexFieldDataService, IndexService indexService, ShardSuggestService shardSuggestService,
|
||||
ShardQueryCache shardQueryCache, ShardBitsetFilterCache shardBitsetFilterCache,
|
||||
|
@ -216,7 +216,7 @@ public class IndexShard extends AbstractIndexShardComponent {
|
|||
this.indexCache = indexCache;
|
||||
this.indexAliasesService = indexAliasesService;
|
||||
this.indexingService = indexingService;
|
||||
this.getService = getService.setIndexShard(this);
|
||||
this.getService = new ShardGetService(this, mapperService);
|
||||
this.termVectorsService = termVectorsService.setIndexShard(this);
|
||||
this.searchService = searchService;
|
||||
this.shardWarmerService = shardWarmerService;
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.index.engine.InternalEngineFactory;
|
|||
import org.elasticsearch.index.fielddata.ShardFieldData;
|
||||
import org.elasticsearch.index.gateway.IndexShardGateway;
|
||||
import org.elasticsearch.index.gateway.IndexShardGatewayService;
|
||||
import org.elasticsearch.index.get.ShardGetService;
|
||||
import org.elasticsearch.index.indexing.ShardIndexingService;
|
||||
import org.elasticsearch.index.indexing.slowlog.ShardSlowLogIndexingService;
|
||||
import org.elasticsearch.index.percolator.PercolatorQueriesRegistry;
|
||||
|
@ -92,7 +91,6 @@ public class IndexShardModule extends AbstractModule {
|
|||
bind(ShardSlowLogIndexingService.class).asEagerSingleton();
|
||||
bind(ShardSearchService.class).asEagerSingleton();
|
||||
bind(ShardSlowLogSearchService.class).asEagerSingleton();
|
||||
bind(ShardGetService.class).asEagerSingleton();
|
||||
bind(ShardFilterCache.class).toInstance(shardFilterCache);
|
||||
bind(ShardQueryCache.class).asEagerSingleton();
|
||||
bind(ShardBitsetFilterCache.class).asEagerSingleton();
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.elasticsearch.index.engine.EngineConfig;
|
|||
import org.elasticsearch.index.engine.EngineFactory;
|
||||
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
||||
import org.elasticsearch.index.fielddata.ShardFieldData;
|
||||
import org.elasticsearch.index.get.ShardGetService;
|
||||
import org.elasticsearch.index.indexing.ShardIndexingService;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.merge.MergeStats;
|
||||
|
@ -71,7 +70,7 @@ public final class ShadowIndexShard extends IndexShard {
|
|||
ThreadPool threadPool, MapperService mapperService,
|
||||
IndexQueryParserService queryParserService, IndexCache indexCache,
|
||||
IndexAliasesService indexAliasesService, ShardIndexingService indexingService,
|
||||
ShardGetService getService, ShardSearchService searchService,
|
||||
ShardSearchService searchService,
|
||||
ShardIndexWarmerService shardWarmerService, ShardFilterCache shardFilterCache,
|
||||
ShardFieldData shardFieldData, PercolatorQueriesRegistry percolatorQueriesRegistry,
|
||||
ShardPercolateService shardPercolateService, CodecService codecService,
|
||||
|
@ -83,7 +82,7 @@ public final class ShadowIndexShard extends IndexShard {
|
|||
NodeEnvironment nodeEnv, ShardPath path, BigArrays bigArrays) throws IOException {
|
||||
super(shardId, indexSettingsService, indicesLifecycle, store,
|
||||
threadPool, mapperService, queryParserService, indexCache, indexAliasesService,
|
||||
indexingService, getService, searchService, shardWarmerService, shardFilterCache,
|
||||
indexingService, searchService, shardWarmerService, shardFilterCache,
|
||||
shardFieldData, percolatorQueriesRegistry, shardPercolateService, codecService,
|
||||
termVectorsService, indexFieldDataService, indexService, shardSuggestService,
|
||||
shardQueryCache, shardBitsetFilterCache, warmer, deletionPolicy, similarityService,
|
||||
|
|
Loading…
Reference in New Issue