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

[7.x][ML] Fix race condition updating reindexing progress (#56135) #56146

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private void startAnalytics(DataFrameAnalyticsTask task, DataFrameAnalyticsConfi
ActionListener<RefreshResponse> refreshListener = ActionListener.wrap(
refreshResponse -> {
// Now we can ensure reindexing progress is complete
task.getStatsHolder().getProgressTracker().updateReindexingProgress(100);
task.setReindexingFinished();

// TODO This could fail with errors. In that case we get stuck with the copied index.
// We could delete the index in case of failure or we could try building the factory before reindexing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class DataFrameAnalyticsTask extends AllocatedPersistentTask implements S
private final StartDataFrameAnalyticsAction.TaskParams taskParams;
@Nullable
private volatile Long reindexingTaskId;
private volatile boolean isReindexingFinished;
private volatile boolean isStopping;
private volatile boolean isMarkAsCompletedCalled;
private final StatsHolder statsHolder;
Expand All @@ -92,6 +93,10 @@ public void setReindexingTaskId(Long reindexingTaskId) {
this.reindexingTaskId = reindexingTaskId;
}

public void setReindexingFinished() {
isReindexingFinished = true;
}

public boolean isStopping() {
return isStopping;
}
Expand Down Expand Up @@ -228,7 +233,7 @@ public void updateReindexTaskProgress(ActionListener<Void> listener) {
private void getReindexTaskProgress(ActionListener<Integer> listener) {
TaskId reindexTaskId = getReindexTaskId();
if (reindexTaskId == null) {
listener.onResponse(statsHolder.getProgressTracker().getReindexingProgressPercent());
listener.onResponse(isReindexingFinished ? 100 : 0);
return;
}

Expand All @@ -244,7 +249,7 @@ private void getReindexTaskProgress(ActionListener<Integer> listener) {
error -> {
if (ExceptionsHelper.unwrapCause(error) instanceof ResourceNotFoundException) {
// The task is not present which means either it has not started yet or it finished.
listener.onResponse(statsHolder.getProgressTracker().getReindexingProgressPercent());
listener.onResponse(isReindexingFinished ? 100 : 0);
} else {
listener.onFailure(error);
}
Expand Down