-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] only retry persistence failures when the failure is intermittent and stop retrying when analytics job is stopping #53725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
benwtrent
merged 6 commits into
elastic:master
from
benwtrent:feature/ml-data-frame-analytics-retry-on-failure-fixes
Mar 19, 2020
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
93a18be
[ML] only retry persistence failures when the failure is intermittent
benwtrent d15da5b
Merge branch 'master' into feature/ml-data-frame-analytics-retry-on-f…
elasticmachine 19c48f7
addressing pr comments
benwtrent 06934f2
Merge branch 'feature/ml-data-frame-analytics-retry-on-failure-fixes'…
benwtrent 7ae4ba1
simplifying joiner and results handler code
benwtrent 7d15d20
addressing pr comments
benwtrent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.logging.log4j.message.ParameterizedMessage; | ||
| import org.elasticsearch.ElasticsearchException; | ||
| import org.elasticsearch.ExceptionsHelper; | ||
| import org.elasticsearch.action.bulk.BulkAction; | ||
| import org.elasticsearch.action.bulk.BulkItemResponse; | ||
| import org.elasticsearch.action.bulk.BulkRequest; | ||
|
|
@@ -33,6 +34,7 @@ | |
| import java.io.IOException; | ||
| import java.time.Duration; | ||
| import java.util.Arrays; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Random; | ||
| import java.util.Set; | ||
|
|
@@ -42,6 +44,22 @@ | |
| import java.util.stream.Collectors; | ||
|
|
||
| public class ResultsPersisterService { | ||
| /** | ||
| * List of rest statuses that we consider irrecoverable | ||
| */ | ||
| public static final Set<RestStatus> IRRECOVERABLE_REST_STATUSES = new HashSet<>( | ||
|
||
| Arrays.asList( | ||
| RestStatus.GONE, | ||
| RestStatus.NOT_IMPLEMENTED, | ||
| RestStatus.NOT_FOUND, | ||
| RestStatus.BAD_REQUEST, | ||
| RestStatus.UNAUTHORIZED, | ||
| RestStatus.FORBIDDEN, | ||
| RestStatus.METHOD_NOT_ALLOWED, | ||
| RestStatus.NOT_ACCEPTABLE | ||
| ) | ||
| ); | ||
|
|
||
| private static final Logger LOGGER = LogManager.getLogger(ResultsPersisterService.class); | ||
|
|
||
| public static final Setting<Integer> PERSIST_RESULTS_MAX_RETRIES = Setting.intSetting( | ||
|
|
@@ -124,9 +142,23 @@ private BulkResponse bulkIndexWithRetry(BulkRequest bulkRequest, | |
| if (bulkResponse.hasFailures() == false) { | ||
| return bulkResponse; | ||
| } | ||
|
|
||
| for (BulkItemResponse itemResponse : bulkResponse.getItems()) { | ||
| if (itemResponse.isFailed()) { | ||
| if (isIrrecoverable(itemResponse.getFailure().getCause())) { | ||
| Throwable unwrappedParticular = ExceptionsHelper.unwrapCause(itemResponse.getFailure().getCause()); | ||
| LOGGER.warn(new ParameterizedMessage( | ||
| "[{}] experienced failure that cannot be automatically retried. Bulk failure message [{}]", | ||
| jobId, | ||
| bulkResponse.buildFailureMessage()), | ||
| unwrappedParticular); | ||
| throw new ElasticsearchException( | ||
| "{} experienced failure that cannot be automatically retried. See logs for bulk failures", | ||
| unwrappedParticular, | ||
| jobId); | ||
| } | ||
| } | ||
| } | ||
| retryContext.nextIteration("index", bulkResponse.buildFailureMessage()); | ||
|
|
||
| // We should only retry the docs that failed. | ||
| bulkRequest = buildNewRequestFromFailures(bulkRequest, bulkResponse); | ||
| } | ||
|
|
@@ -148,12 +180,28 @@ public SearchResponse searchWithRetry(SearchRequest searchRequest, | |
| } catch (ElasticsearchException e) { | ||
| LOGGER.warn("[" + jobId + "] Exception while executing search action", e); | ||
| failureMessage = e.getDetailedMessage(); | ||
| if (isIrrecoverable(e)) { | ||
| LOGGER.warn(new ParameterizedMessage("[{}] experienced failure that cannot be automatically retried", jobId), e); | ||
| throw new ElasticsearchException("{} experienced failure that cannot be automatically retried", e, jobId); | ||
| } | ||
| } | ||
|
|
||
| retryContext.nextIteration("search", failureMessage); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param ex The exception to check | ||
| * @return true when the failure will persist no matter how many times we retry. | ||
| */ | ||
| private static boolean isIrrecoverable(Exception ex) { | ||
| Throwable t = ExceptionsHelper.unwrapCause(ex); | ||
| if (t instanceof ElasticsearchException) { | ||
| return IRRECOVERABLE_REST_STATUSES.contains(((ElasticsearchException) t).status()); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * {@link RetryContext} object handles logic that is executed between consecutive retries of an action. | ||
| * | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be final and passed in the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the retry persistence logic depends on information stored within
AnalyticsResultProcessorwe would either have to make a Builder or a Factory class that we then pass toAnalyticsResultProcessorwhich constructs a new joiner from that passed factory.This option just seemed simpler and less complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it. Please also consider the following approach which might be even less complex:
Add
isCancelledfield andcancel()method toDataFrameRowsJoinerclass. InAnalyticsResultProcessor::cancel(), you can also cancel the joiner:Then there is no need to pass the
Supplieras you've already passed the actualisCancelledvalue.