Return empty completion stats if engine throws an exception

If the index shard is not started yet the underlying engine can
throw an exception since not everything is initialized. This can
happen if a shard is just about starting up or recovering / initalizing
and stats are requested.

Closes #3619
This commit is contained in:
Simon Willnauer 2013-09-05 09:44:41 +02:00
parent 8257aba166
commit 764a519627
1 changed files with 23 additions and 20 deletions

View File

@ -82,7 +82,6 @@ import org.elasticsearch.search.suggest.completion.Completion090PostingsFormat;
import org.elasticsearch.search.suggest.completion.CompletionStats;
import org.elasticsearch.threadpool.ThreadPool;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.channels.ClosedByInterruptException;
import java.util.concurrent.ScheduledFuture;
@ -457,16 +456,16 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
@Override
public DocsStats docStats() {
Engine.Searcher searcher = null;
try {
searcher = engine.searcher();
return new DocsStats(searcher.reader().numDocs(), searcher.reader().numDeletedDocs());
} catch (Exception e) {
return new DocsStats();
} finally {
if (searcher != null) {
final Engine.Searcher searcher = engine.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);
return new DocsStats();
}
}
@ -489,7 +488,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
public StoreStats storeStats() {
try {
return store.stats();
} catch (IOException e) {
} catch (Throwable e) {
logger.debug("Can not build store stats from engine shard state [{}]", e, state);
return new StoreStats();
}
}
@ -532,19 +532,22 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
@Override
public CompletionStats completionStats(String... fields) {
CompletionStats completionStats = new CompletionStats();
Engine.Searcher searcher = engine().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));
try{
final Engine.Searcher searcher = engine.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));
}
} finally {
searcher.release();
}
} finally {
searcher.release();
} catch (Throwable e) {
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.
}
return completionStats;
}