mirror of https://github.com/apache/druid.git
Merge pull request #573 from metamx/task-fail-on-exception
fail task on exception
This commit is contained in:
commit
89d8e66ce6
|
@ -452,8 +452,19 @@ public class RemoteTaskRunner implements TaskRunner, TaskLogStreamer
|
||||||
List<RemoteTaskRunnerWorkItem> copy = Lists.newArrayList(pendingTasks.values());
|
List<RemoteTaskRunnerWorkItem> copy = Lists.newArrayList(pendingTasks.values());
|
||||||
for (RemoteTaskRunnerWorkItem taskRunnerWorkItem : copy) {
|
for (RemoteTaskRunnerWorkItem taskRunnerWorkItem : copy) {
|
||||||
String taskId = taskRunnerWorkItem.getTaskId();
|
String taskId = taskRunnerWorkItem.getTaskId();
|
||||||
if (tryAssignTask(pendingTaskPayloads.get(taskId), taskRunnerWorkItem)) {
|
try {
|
||||||
pendingTaskPayloads.remove(taskId);
|
if (tryAssignTask(pendingTaskPayloads.get(taskId), taskRunnerWorkItem)) {
|
||||||
|
pendingTaskPayloads.remove(taskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.makeAlert(e, "Exception while trying to assign task")
|
||||||
|
.addData("taskId", taskRunnerWorkItem.getTaskId())
|
||||||
|
.emit();
|
||||||
|
RemoteTaskRunnerWorkItem workItem = pendingTasks.remove(taskId);
|
||||||
|
if (workItem != null) {
|
||||||
|
workItem.setResult(TaskStatus.failure(taskId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,33 +518,25 @@ public class RemoteTaskRunner implements TaskRunner, TaskLogStreamer
|
||||||
* @param taskRunnerWorkItem - the task to assign
|
* @param taskRunnerWorkItem - the task to assign
|
||||||
* @return true iff the task is now assigned
|
* @return true iff the task is now assigned
|
||||||
*/
|
*/
|
||||||
private boolean tryAssignTask(final Task task, final RemoteTaskRunnerWorkItem taskRunnerWorkItem)
|
private boolean tryAssignTask(final Task task, final RemoteTaskRunnerWorkItem taskRunnerWorkItem) throws Exception
|
||||||
{
|
{
|
||||||
try {
|
Preconditions.checkNotNull(task, "task");
|
||||||
Preconditions.checkNotNull(task, "task");
|
Preconditions.checkNotNull(taskRunnerWorkItem, "taskRunnerWorkItem");
|
||||||
Preconditions.checkNotNull(taskRunnerWorkItem, "taskRunnerWorkItem");
|
Preconditions.checkArgument(task.getId().equals(taskRunnerWorkItem.getTaskId()), "task id != workItem id");
|
||||||
Preconditions.checkArgument(task.getId().equals(taskRunnerWorkItem.getTaskId()), "task id != workItem id");
|
|
||||||
|
|
||||||
if (runningTasks.containsKey(task.getId()) || findWorkerRunningTask(task.getId()) != null) {
|
if (runningTasks.containsKey(task.getId()) || findWorkerRunningTask(task.getId()) != null) {
|
||||||
log.info("Task[%s] already running.", task.getId());
|
log.info("Task[%s] already running.", task.getId());
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// Nothing running this task, announce it in ZK for a worker to run it
|
||||||
|
ZkWorker zkWorker = findWorkerForTask(task);
|
||||||
|
if (zkWorker != null) {
|
||||||
|
announceTask(task, zkWorker, taskRunnerWorkItem);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Nothing running this task, announce it in ZK for a worker to run it
|
return false;
|
||||||
ZkWorker zkWorker = findWorkerForTask(task);
|
|
||||||
if (zkWorker != null) {
|
|
||||||
announceTask(task, zkWorker, taskRunnerWorkItem);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
|
||||||
log.makeAlert(e, "Exception while trying to run task")
|
|
||||||
.addData("taskId", taskRunnerWorkItem.getTaskId())
|
|
||||||
.emit();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue