Skip to content
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

[Transform] make shouldStopAtCheckpoint more robust #70461

Merged
merged 5 commits into from
Mar 22, 2021

Conversation

hendrikmuhs
Copy link

shouldStopAtCheckpoint tells transform to stop at the next checkpoint, if
this API is called while a checkpoint is finishing, it can cause a race condition
in state persistence. This is similar to #69551, but this time in a different
place.

With this change _stop?shouldStopAtCheckpoint=true does not call doSaveState
if indexer is shutting down. Still it ensures the job stops after the indexer has
shutdown. Apart from that the change fixes: a logging problem, it adds error
handling in case of a timeout during _stop?shouldStopAtCheckpoint=true. Some
logic has been moved from the task to the indexer.

fixes #70416

… stops

if stopAtCheckpoint has been called in between. This change also fixes a
logging problem and ensures a timeout error gets logged.

fixes elastic#70416
@hendrikmuhs hendrikmuhs marked this pull request as ready for review March 18, 2021 14:57
@elasticmachine elasticmachine added the Team:ML Meta label for the ML team label Mar 18, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

Comment on lines -1117 to +1144
if (stopCalledDuringIndexerThreadShutdown) {
doSaveState(IndexerState.STOPPED, getPosition(), () -> {});
if (saveStateRequestedDuringIndexerThreadShutdown) {
// if stop has been called and set shouldStopAtCheckpoint to true,
// we should stop if we just finished a checkpoint
if (context.shouldStopAtCheckpoint() && nextCheckpoint == null) {
stop();
}
doSaveState(getState(), getPosition(), () -> {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bad bug :/

Previously, even if we were waiting to stop at a checkpoint we would just set the indexer to stopped and save state. No wonder we had two things attempting to save state + a weird race condition

@@ -719,9 +737,12 @@ private synchronized boolean addSetStopAtCheckpointListener(

synchronized void stopAndSaveState() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this name has been the same for a while.

But I think something like stopAndMaybeSaveState is better is it will only save state if the indexer is NOT already shutting down + the indexer stopped.

if (state == IndexerState.STOPPED) {
getIndexer().stopAndSaveState();
}
getIndexer().stopAndSaveState();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Co-authored-by: Przemysław Witek <[email protected]>
Copy link
Contributor

@przemekwitek przemekwitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hendrikmuhs hendrikmuhs merged commit cc28159 into elastic:master Mar 22, 2021
@hendrikmuhs hendrikmuhs deleted the transform-#70416 branch March 22, 2021 10:28
hendrikmuhs pushed a commit that referenced this pull request Mar 22, 2021
shouldStopAtCheckpoint tells transform to stop at the next checkpoint, if
this API is called while a checkpoint is finishing, it can cause a race condition
in state persistence. This is similar to #69551, but this time in a different
place.

With this change _stop?shouldStopAtCheckpoint=true does not call doSaveState
if indexer is shutting down. Still it ensures the job stops after the indexer has
shutdown. Apart from that the change fixes: a logging problem, it adds error
handling in case of a timeout during _stop?shouldStopAtCheckpoint=true. Some
logic has been moved from the task to the indexer.

fixes #70416
hendrikmuhs pushed a commit that referenced this pull request Apr 6, 2021
…71343)

shouldStopAtCheckpoint tells transform to stop at the next checkpoint, if
this API is called while a checkpoint is finishing, it can cause a race condition
in state persistence. This is similar to #69551, but this time in a different
place.

With this change _stop?shouldStopAtCheckpoint=true does not call doSaveState
if indexer is shutting down. Still it ensures the job stops after the indexer has
shutdown. Apart from that the change fixes: a logging problem, it adds error
handling in case of a timeout during _stop?shouldStopAtCheckpoint=true. Some
logic has been moved from the task to the indexer.

fixes #70416
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CI] TransformIT.testStopWaitForCheckpoint
5 participants