From 5c00dc577388c9efbb13e612dec88a49b7165141 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 9 Sep 2013 21:16:38 +0200 Subject: [PATCH] Rename IndexShard#searcher() to #acquireSearcher() Based on recent bugs ( #3652 ) where searchers were acquired multiple times but never released 'IndexShard#searcher()' has not a more accurate name. Closes #3653 --- .../indices/status/TransportIndicesStatusAction.java | 2 +- .../validate/query/TransportValidateQueryAction.java | 2 +- .../elasticsearch/action/count/TransportCountAction.java | 2 +- .../action/suggest/TransportSuggestAction.java | 2 +- .../index/percolator/PercolatorQueriesRegistry.java | 2 +- .../org/elasticsearch/index/shard/service/IndexShard.java | 2 +- .../index/shard/service/InternalIndexShard.java | 6 +++--- .../index/termvectors/ShardTermVectorService.java | 2 +- .../org/elasticsearch/indices/ttl/IndicesTTLService.java | 2 +- .../org/elasticsearch/percolator/PercolatorService.java | 8 ++++---- src/main/java/org/elasticsearch/search/SearchService.java | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java b/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java index 22b1ba12864..85eea759054 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java @@ -157,7 +157,7 @@ public class TransportIndicesStatusAction extends TransportBroadcastOperationAct // shardStatus.estimatedFlushableMemorySize = indexShard.estimateFlushableMemorySize(); shardStatus.translogId = indexShard.translog().currentId(); shardStatus.translogOperations = indexShard.translog().estimatedNumberOfOperations(); - Engine.Searcher searcher = indexShard.searcher(); + Engine.Searcher searcher = indexShard.acquireSearcher(); try { shardStatus.docs = new DocsStatus(); shardStatus.docs.numDocs = searcher.reader().numDocs(); 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 724a1e5964c..8965140389e 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 @@ -172,7 +172,7 @@ public class TransportValidateQueryAction extends TransportBroadcastOperationAct } else { SearchContext.setCurrent(new DefaultSearchContext(0, new ShardSearchRequest().types(request.types()), - null, indexShard.searcher(), indexService, indexShard, + null, indexShard.acquireSearcher(), indexService, indexShard, scriptService, cacheRecycler)); try { ParsedQuery parsedQuery = queryParserService.parse(request.querySource()); diff --git a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java index 22f89dae4e1..ab5ff84d614 100644 --- a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java +++ b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java @@ -154,7 +154,7 @@ public class TransportCountAction extends TransportBroadcastOperationActiontrue if this shard can ignore a recovery attempt made to it (since the already doing/done it) diff --git a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index a6ad5386343..47e8707d5b3 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -457,7 +457,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I @Override public DocsStats docStats() { try { - final Engine.Searcher searcher = searcher(); + final Engine.Searcher searcher = acquireSearcher(); try { return new DocsStats(searcher.reader().numDocs(), searcher.reader().numDeletedDocs()); } finally { @@ -533,7 +533,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I public CompletionStats completionStats(String... fields) { CompletionStats completionStats = new CompletionStats(); try{ - final Engine.Searcher currentSearcher = searcher(); + final Engine.Searcher currentSearcher = acquireSearcher(); try { PostingsFormat postingsFormat = this.codecService.postingsFormatService().get(Completion090PostingsFormat.CODEC_NAME).get(); if (postingsFormat instanceof Completion090PostingsFormat) { @@ -591,7 +591,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I } @Override - public Engine.Searcher searcher() { + public Engine.Searcher acquireSearcher() { readAllowed(); return engine.searcher(); } diff --git a/src/main/java/org/elasticsearch/index/termvectors/ShardTermVectorService.java b/src/main/java/org/elasticsearch/index/termvectors/ShardTermVectorService.java index c925461339b..c3215e1af0e 100644 --- a/src/main/java/org/elasticsearch/index/termvectors/ShardTermVectorService.java +++ b/src/main/java/org/elasticsearch/index/termvectors/ShardTermVectorService.java @@ -58,7 +58,7 @@ public class ShardTermVectorService extends AbstractIndexShardComponent { } public TermVectorResponse getTermVector(TermVectorRequest request) { - final Engine.Searcher searcher = indexShard.searcher(); + final Engine.Searcher searcher = indexShard.acquireSearcher(); IndexReader topLevelReader = searcher.reader(); final TermVectorResponse termVectorResponse = new TermVectorResponse(request.index(), request.type(), request.id()); final Term uidTerm = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(request.type(), request.id())); diff --git a/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java b/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java index a2a0841fd97..5eaefea54c6 100644 --- a/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java +++ b/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java @@ -179,7 +179,7 @@ public class IndicesTTLService extends AbstractLifecycleComponent shardsToPurge) { for (IndexShard shardToPurge : shardsToPurge) { Query query = NumericRangeQuery.newLongRange(TTLFieldMapper.NAME, null, System.currentTimeMillis(), false, true); - Engine.Searcher searcher = shardToPurge.searcher(); + Engine.Searcher searcher = shardToPurge.acquireSearcher(); try { logger.debug("[{}][{}] purging shard", shardToPurge.routingEntry().index(), shardToPurge.routingEntry().id()); ExpiredDocsCollector expiredDocsCollector = new ExpiredDocsCollector(shardToPurge.routingEntry().index()); diff --git a/src/main/java/org/elasticsearch/percolator/PercolatorService.java b/src/main/java/org/elasticsearch/percolator/PercolatorService.java index 8b48da4cb33..1848f5b2bf7 100644 --- a/src/main/java/org/elasticsearch/percolator/PercolatorService.java +++ b/src/main/java/org/elasticsearch/percolator/PercolatorService.java @@ -416,7 +416,7 @@ public class PercolatorService extends AbstractComponent { @Override public PercolateShardResponse doPercolate(PercolateShardRequest request, PercolateContext context) { long count = 0; - Engine.Searcher percolatorSearcher = context.indexShard().searcher(); + Engine.Searcher percolatorSearcher = context.indexShard().acquireSearcher(); try { Count countCollector = count(logger, context); queryBasedPercolating(percolatorSearcher, context, countCollector); @@ -515,7 +515,7 @@ public class PercolatorService extends AbstractComponent { @Override public PercolateShardResponse doPercolate(PercolateShardRequest request, PercolateContext context) { - Engine.Searcher percolatorSearcher = context.indexShard().searcher(); + Engine.Searcher percolatorSearcher = context.indexShard().acquireSearcher(); try { Match match = match(logger, context, highlightPhase); queryBasedPercolating(percolatorSearcher, context, match); @@ -548,7 +548,7 @@ public class PercolatorService extends AbstractComponent { @Override public PercolateShardResponse doPercolate(PercolateShardRequest request, PercolateContext context) { - Engine.Searcher percolatorSearcher = context.indexShard().searcher(); + Engine.Searcher percolatorSearcher = context.indexShard().acquireSearcher(); try { MatchAndScore matchAndScore = matchAndScore(logger, context, highlightPhase); queryBasedPercolating(percolatorSearcher, context, matchAndScore); @@ -658,7 +658,7 @@ public class PercolatorService extends AbstractComponent { @Override public PercolateShardResponse doPercolate(PercolateShardRequest request, PercolateContext context) { - Engine.Searcher percolatorSearcher = context.indexShard().searcher(); + Engine.Searcher percolatorSearcher = context.indexShard().acquireSearcher(); try { MatchAndSort matchAndSort = QueryCollector.matchAndSort(logger, context); queryBasedPercolating(percolatorSearcher, context, matchAndSort); diff --git a/src/main/java/org/elasticsearch/search/SearchService.java b/src/main/java/org/elasticsearch/search/SearchService.java index f74fe05d4ff..f02a1833262 100644 --- a/src/main/java/org/elasticsearch/search/SearchService.java +++ b/src/main/java/org/elasticsearch/search/SearchService.java @@ -456,7 +456,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; + Engine.Searcher engineSearcher = searcher == null ? indexShard.acquireSearcher() : searcher; SearchContext context = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, engineSearcher, indexService, indexShard, scriptService, cacheRecycler); SearchContext.setCurrent(context); try {