[ML] Only clear scroll whan a scroll id exists (elastic/x-pack-elasticsearch#3148)

The issue here is that if the first search request fails
(initScroll), then we do not have a scroll_id. However,
in order to retry the search, we reset the scroll. That
involves clearing the current search, but since we do
not have a scroll_id, the clear scroll request fails.
We end up reporting the failure for the scroll clearing,
rather than the actual problem.

This commit fixes that by avoiding clearing the scroll
when the scroll_id is null.

relates elastic/x-pack-elasticsearch#3146

Original commit: elastic/x-pack-elasticsearch@b5086028f6
This commit is contained in:
Dimitris Athanasiou 2017-11-28 16:48:24 +00:00 committed by GitHub
parent b6f322e72e
commit d96be6c51f
2 changed files with 14 additions and 1 deletions

View File

@ -214,7 +214,9 @@ class ScrollDataExtractor implements DataExtractor {
} }
private void resetScroll() { private void resetScroll() {
if (scrollId != null) {
clearScroll(scrollId); clearScroll(scrollId);
}
scrollId = null; scrollId = null;
} }

View File

@ -384,6 +384,17 @@ public class ScrollDataExtractorTests extends ESTestCase {
expectThrows(SearchPhaseExecutionException.class, () -> extractor.next()); expectThrows(SearchPhaseExecutionException.class, () -> extractor.next());
} }
public void testSearchPhaseExecutionExceptionOnInitScroll() throws IOException {
TestDataExtractor extractor = new TestDataExtractor(1000L, 2000L);
extractor.setNextResponse(createResponseWithShardFailures());
extractor.setNextResponse(createResponseWithShardFailures());
expectThrows(IOException.class, () -> extractor.next());
assertThat(capturedClearScrollIds.isEmpty(), is(true));
}
public void testDomainSplitScriptField() throws IOException { public void testDomainSplitScriptField() throws IOException {
SearchSourceBuilder.ScriptField withoutSplit = new SearchSourceBuilder.ScriptField( SearchSourceBuilder.ScriptField withoutSplit = new SearchSourceBuilder.ScriptField(