From fcbd0dddcdbea6535271303604ef76821931d40e Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 29 Jun 2015 20:45:59 +0200 Subject: [PATCH] Don't pull the engine for access to the QueryCachingPolicy --- .../org/elasticsearch/index/shard/IndexShard.java | 5 ++++- .../java/org/elasticsearch/search/SearchService.java | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 3a11dd64fbd..7c3caf09c7d 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -254,7 +254,6 @@ public class IndexShard extends AbstractIndexShardComponent { cachingPolicy = new UsageTrackingQueryCachingPolicy(); } this.engineConfig = newEngineConfig(translogConfig, cachingPolicy); - this.indexShardOperationCounter = new IndexShardOperationCounter(logger, shardId); } @@ -324,6 +323,10 @@ public class IndexShard extends AbstractIndexShardComponent { return this.shardRouting; } + public QueryCachingPolicy getQueryCachingPolicy() { + return this.engineConfig.getQueryCachingPolicy(); + } + /** * Updates the shards routing entry. This mutate the shards internal state depending * on the changes that get introduced by the new routing value. This method will persist shard level metadata diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index 64b8b273cca..ff477f6ec26 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -372,9 +372,10 @@ public class SearchService extends AbstractLifecycleComponent { public QuerySearchResult executeQueryPhase(QuerySearchRequest request) { final SearchContext context = findContext(request.id()); contextProcessing(context); + IndexShard indexShard = context.indexShard(); try { - final IndexCache indexCache = context.indexShard().indexService().cache(); - final QueryCachingPolicy cachingPolicy = context.indexShard().engine().config().getQueryCachingPolicy(); + final IndexCache indexCache = indexShard.indexService().cache(); + final QueryCachingPolicy cachingPolicy = indexShard.getQueryCachingPolicy(); context.searcher().dfSource(new CachedDfSource(context.searcher().getIndexReader(), request.dfs(), context.similarityService().similarity(), indexCache.query(), cachingPolicy)); } catch (Throwable e) { @@ -382,7 +383,7 @@ public class SearchService extends AbstractLifecycleComponent { cleanContext(context); throw new QueryPhaseExecutionException(context, "Failed to set aggregated df", e); } - ShardSearchStats shardSearchStats = context.indexShard().searchService(); + ShardSearchStats shardSearchStats = indexShard.searchService(); try { shardSearchStats.onPreQueryPhase(context); long time = System.nanoTime(); @@ -448,8 +449,9 @@ public class SearchService extends AbstractLifecycleComponent { final SearchContext context = findContext(request.id()); contextProcessing(context); try { - final IndexCache indexCache = context.indexShard().indexService().cache(); - final QueryCachingPolicy cachingPolicy = context.indexShard().engine().config().getQueryCachingPolicy(); + final IndexShard indexShard = context.indexShard(); + final IndexCache indexCache = indexShard.indexService().cache(); + final QueryCachingPolicy cachingPolicy = indexShard.getQueryCachingPolicy(); context.searcher().dfSource(new CachedDfSource(context.searcher().getIndexReader(), request.dfs(), context.similarityService().similarity(), indexCache.query(), cachingPolicy)); } catch (Throwable e) {