Skip to content

Commit

Permalink
[ML-DataFrame] improve error message for timeout case in stop (#46131)
Browse files Browse the repository at this point in the history
improve error message if stopping of transform times out.

related #45610
  • Loading branch information
Hendrik Muhs committed Sep 6, 2019
1 parent 78824cc commit ab5f09d
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,55 @@ private void waitForDataFrameStopped(Set<String> persistentTaskIds,

listener.onFailure(new ElasticsearchStatusException(message, RestStatus.CONFLICT));
},
listener::onFailure
e -> {
// waitForPersistentTasksCondition throws a IllegalStateException on timeout
if (e instanceof IllegalStateException && e.getMessage().startsWith("Timed out")) {
PersistentTasksCustomMetaData persistentTasksCustomMetaData = clusterService.state().metaData()
.custom(PersistentTasksCustomMetaData.TYPE);

if (persistentTasksCustomMetaData == null) {
listener.onResponse(new Response(Boolean.TRUE));
return;
}

// collect which tasks are still running
Set<String> stillRunningTasks = new HashSet<>();
for (String persistentTaskId : persistentTaskIds) {
if (persistentTasksCustomMetaData.getTask(persistentTaskId) != null) {
stillRunningTasks.add(persistentTaskId);
}
}

if (stillRunningTasks.isEmpty()) {
// should not happen
listener.onResponse(new Response(Boolean.TRUE));
return;
} else {
StringBuilder message = new StringBuilder();
if (persistentTaskIds.size() - stillRunningTasks.size() - exceptions.size() > 0) {
message.append("Successfully stopped [");
message.append(persistentTaskIds.size() - stillRunningTasks.size() - exceptions.size());
message.append("] transforms. ");
}

if (exceptions.size() > 0) {
message.append("Could not stop the transforms ");
message.append(exceptions.keySet());
message.append(" as they were failed. Use force stop to stop the transforms. ");
}

if (stillRunningTasks.size() > 0) {
message.append("Could not stop the transforms ");
message.append(stillRunningTasks);
message.append(" as they timed out.");
}

listener.onFailure(new ElasticsearchStatusException(message.toString(), RestStatus.REQUEST_TIMEOUT));
return;
}
}
listener.onFailure(e);
}
));
}
}

0 comments on commit ab5f09d

Please sign in to comment.