diff options
author | Jason Tedor <jason@tedor.me> | 2017-05-27 15:40:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-27 15:40:37 -0400 |
commit | 3448028af7bd026059088052d57663fe4d00005b (patch) | |
tree | 05b185ac8d71a5e5299f744dcecf209b75257eb5 /core/src/main/java/org/elasticsearch/search | |
parent | 5da8ce8318efda1fdcc367d97dc294feaf6285cc (diff) |
Avoid double decrement on current query counter
This commit fixes a double decrement bug on the current query
counter. The double decrement arises in a situation when the fetch phase
is inlined for a query that is only touching one shard. After the query
phase succeeds we decrement the current query counter. If the fetch
phase ultimately fails, an exception is thrown and we decrement the
current query counter again in the catch block. We also add assertions
that all current stats counters remain non-negative at all
times.
Relates #24922
Diffstat (limited to 'core/src/main/java/org/elasticsearch/search')
-rw-r--r-- | core/src/main/java/org/elasticsearch/search/SearchService.java | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index 06eb435e60..fef20f44f5 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -251,6 +251,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv final SearchContext context = createAndPutContext(request); final SearchOperationListener operationListener = context.indexShard().getSearchOperationListener(); context.incRef(); + boolean queryPhaseSuccess = false; try { context.setTask(task); operationListener.onPreQueryPhase(context); @@ -265,6 +266,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv contextProcessedSuccessfully(context); } final long afterQueryTime = System.nanoTime(); + queryPhaseSuccess = true; operationListener.onQueryPhase(context, afterQueryTime - time); if (request.numberOfShards() == 1) { return executeFetchPhase(context, operationListener, afterQueryTime); @@ -276,7 +278,9 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv e = (e.getCause() == null || e.getCause() instanceof Exception) ? (Exception) e.getCause() : new ElasticsearchException(e.getCause()); } - operationListener.onFailedQueryPhase(context); + if (!queryPhaseSuccess) { + operationListener.onFailedQueryPhase(context); + } logger.trace("Query phase failed", e); processFailure(context, e); throw ExceptionsHelper.convertToRuntime(e); |