From 84d520b0e59099ce7bff2714bf82773554e55f69 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Wed, 9 Jan 2019 13:35:41 +0100 Subject: [PATCH] Throw an ISE rather than an hard assertion in SearchPhaseController#getTotalHits This change turns an assertion into an IllegalStateException in SearchPhaseController#getTotalHits. The goal is to help identify the cause of the failures in https://github.com/elastic/elasticsearch/issues/37179 which seems to fail only in CI. The assertion will be restored when the issue is solved (NORELEASE). --- .../action/search/SearchPhaseController.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java b/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java index 418d95b2077..8fada8938f8 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java @@ -760,7 +760,13 @@ public final class SearchPhaseController { if (trackTotalHitsUpTo == SearchContext.TRACK_TOTAL_HITS_DISABLED) { return null; } else if (trackTotalHitsUpTo == SearchContext.TRACK_TOTAL_HITS_ACCURATE) { - assert totalHitsRelation == Relation.EQUAL_TO; + // NORELEASE The assertion below has been replaced by a runtime exception in order to debug + // https://github.com/elastic/elasticsearch/issues/37179. + // The assertion should be restored and the exception removed when this issue is solved. + // assert totalHitsRelation == Relation.EQUAL_TO; + if (totalHitsRelation != Relation.EQUAL_TO) { + throw new IllegalStateException("Expected accurate total hits but got " + new TotalHits(totalHits, totalHitsRelation)); + } return new TotalHits(totalHits, totalHitsRelation); } else { if (totalHits < trackTotalHitsUpTo) {