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

Do not retry ON_DEMAND tasks which were killed by user request. #2059

Merged
merged 5 commits into from
Jan 28, 2020
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 @@ -849,10 +849,19 @@ private boolean shouldRetryImmediately(SingularityRequest request, SingularityDe
return false;
}

if (task.isPresent()
&& task.get().getTaskRequest().getPendingTask().getPendingTaskId().getPendingType() == PendingType.IMMEDIATE
&& request.getRequestType() == RequestType.SCHEDULED) {
return false; // don't retry UI triggered scheduled jobs (UI triggered on-demand jobs are okay to retry though)
if (task.isPresent()) {
if (task.get().getTaskRequest().getPendingTask().getPendingTaskId().getPendingType() == PendingType.IMMEDIATE
&& request.getRequestType() == RequestType.SCHEDULED) {
return false; // don't retry UI triggered scheduled jobs (UI triggered on-demand jobs are okay to retry though)
}

Optional<SingularityTaskHistoryUpdate> taskHistoryUpdate = taskManager.getTaskHistoryUpdate(task.get().getTaskId(), ExtendedTaskState.TASK_CLEANING);

if (taskHistoryUpdate.isPresent()
&& request.getRequestType() == RequestType.ON_DEMAND
&& taskHistoryUpdate.get().getStatusMessage().orElse("").contains("USER_REQUESTED")) {
return false; // don't retry one-off launches of on-demand jobs if they were killed by the user
}
}

final int numRetriesInARow = deployStatistics.getNumSequentialRetries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,40 @@ public void testRunNowOnDemandJobMayRetryOnFailure() {
Assertions.assertEquals(1, deployStatistics.getNumSequentialRetries());
}

@Test
public void testRunNowOnDemandJobsDoNotRetryAfterUserRequestedKill() {
initRequestWithType(RequestType.ON_DEMAND, false);
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
SingularityRequest newRequest = request.toBuilder().setNumRetriesOnFailure(Optional.of(2)).build();
requestResource.postRequest(newRequest, singularityUser);
initFirstDeploy();

requestResource.scheduleImmediately(singularityUser, requestId, new SingularityRunNowRequestBuilder().setMessage("foo bar").build());
scheduler.drainPendingQueue();
resourceOffers();

SingularityTask task = taskManager.getActiveTasks().get(0);
taskManager.saveTaskCleanup(new SingularityTaskCleanup(
Optional.of(singularityUser.getId()),
TaskCleanupType.USER_REQUESTED,
System.currentTimeMillis(),
task.getTaskId(),
Optional.empty(),
Optional.empty(),
Optional.empty())
);
cleaner.drainCleanupQueue();
statusUpdate(task, TaskState.TASK_KILLED);
scheduler.drainPendingQueue();

SingularityDeployStatistics deployStatistics = deployManager.getDeployStatistics(task.getTaskId().getRequestId(), task.getTaskId().getDeployId()).get();

Assertions.assertEquals(0, taskManager.getPendingTaskIds().size());
Assertions.assertEquals(MesosTaskState.TASK_KILLED, deployStatistics.getLastTaskState().get().toTaskState().get());
Assertions.assertEquals(0, deployStatistics.getNumFailures());
Assertions.assertEquals(0, deployStatistics.getNumSequentialRetries());
}

@Test
public void testOnDemandRunNowJobRespectsSpecifiedRunAtTime() {
initOnDemandRequest();
Expand Down