From 76cc8c3549cebb10eebf73ee2c6829bb2db04e55 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 9 Sep 2013 17:18:23 +0200 Subject: [PATCH] Only pull searcher once during completion stats The inner call to the completion stats pulled a second searcher that never got released causing the underlying readers to never get closed unless the node is shut down. This was triggered with literally each stats call including the completion stats even if no completion service was used on the index. Closes #3652 --- .../index/shard/service/InternalIndexShard.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 9e66799ba0b..a6ad5386343 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -457,14 +457,14 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I @Override public DocsStats docStats() { try { - final Engine.Searcher searcher = engine.searcher(); + final Engine.Searcher searcher = searcher(); try { return new DocsStats(searcher.reader().numDocs(), searcher.reader().numDeletedDocs()); } finally { searcher.release(); } } catch (Throwable e) { - logger.debug("Can not docStats completion stats from engine shard state [{}]", e, state); + logger.debug("Can not build 'doc stats' from engine shard state [{}]", e, state); return new DocsStats(); } } @@ -489,7 +489,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I try { return store.stats(); } catch (Throwable e) { - logger.debug("Can not build store stats from engine shard state [{}]", e, state); + logger.debug("Can not build 'store stats' from engine shard state [{}]", e, state); return new StoreStats(); } } @@ -533,18 +533,18 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I public CompletionStats completionStats(String... fields) { CompletionStats completionStats = new CompletionStats(); try{ - final Engine.Searcher searcher = engine.searcher(); + final Engine.Searcher currentSearcher = searcher(); try { PostingsFormat postingsFormat = this.codecService.postingsFormatService().get(Completion090PostingsFormat.CODEC_NAME).get(); if (postingsFormat instanceof Completion090PostingsFormat) { Completion090PostingsFormat completionPostingsFormat = (Completion090PostingsFormat) postingsFormat; - completionStats.add(completionPostingsFormat.completionStats(searcher().reader(), fields)); + completionStats.add(completionPostingsFormat.completionStats(currentSearcher.reader(), fields)); } } finally { - searcher.release(); + currentSearcher.release(); } } catch (Throwable e) { - logger.debug("Can not build completion stats from engine shard state [{}]", e, state); + logger.debug("Can not build 'completion stats' from engine shard state [{}]", e, state); // if we are called during engine stop / start or before start we can run into Exceptions // like the engine is already closed or no saercher is present at this point. }