Skip to content

Commit 1cb7896

Browse files
[7.4][ML] Ensure data frame analytics task is only marked completed once (#47119) (#47158)
Closes #46907
1 parent 7ada968 commit 1cb7896

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ public static class DataFrameAnalyticsTask extends AllocatedPersistentTask imple
419419
private volatile Long reindexingTaskId;
420420
private volatile boolean isReindexingFinished;
421421
private volatile boolean isStopping;
422+
private volatile boolean isMarkAsCompletedCalled;
422423
private final ProgressTracker progressTracker = new ProgressTracker();
423424

424425
public DataFrameAnalyticsTask(long id, String type, String action, TaskId parentTask, Map<String, String> headers,
@@ -460,10 +461,17 @@ protected void onCancelled() {
460461
public void markAsCompleted() {
461462
// It is possible that the stop API has been called in the meantime and that
462463
// may also cause this method to be called. We check whether we have already
463-
// been marked completed to avoid doing it twice.
464-
if (isCompleted() == false) {
465-
persistProgress(() -> super.markAsCompleted());
464+
// been marked completed to avoid doing it twice. We need to capture that
465+
// locally instead of relying to isCompleted() because of the asynchronous
466+
// persistence of progress.
467+
synchronized (this) {
468+
if (isMarkAsCompletedCalled) {
469+
return;
470+
}
471+
isMarkAsCompletedCalled = true;
466472
}
473+
474+
persistProgress(() -> super.markAsCompleted());
467475
}
468476

469477
@Override

0 commit comments

Comments
 (0)