1、Worker向Master三次汇报
注意 : RUNNING_INFO更新有问题,因为根本就不会更新PID,因为都没有传递过去PID,所以这个有什么用呢?PID还是最后FINISH进行更新的,这不合理,如果任务执行时间比较长,我恰好要看PID,是不是看不到,等到任务结束才能看到
2、修复
Worker端 :
org.apache.dolphinscheduler.plugin.task.api.AbstractCommandExecutor#run
org.apache.dolphinscheduler.server.worker.runner.TaskCallbackImpl#updateTaskInstanceInfo
Master端 :
org.apache.dolphinscheduler.server.master.processor.queue.TaskEvent#newUpdatePidEvent
最后其实由 org.apache.dolphinscheduler.server.master.event.TaskUpdatePidEventHandler 来处理
public void handleTaskEvent(TaskEvent taskEvent) throws TaskEventHandleError {
int taskInstanceId = taskEvent.getTaskInstanceId();
int processInstanceId = taskEvent.getProcessInstanceId();
WorkflowExecuteRunnable workflowExecuteRunnable =
processInstanceExecCacheManager.getByProcessInstanceId(processInstanceId);
if (workflowExecuteRunnable == null) {
sendAckToWorker(taskEvent);
throw new TaskEventHandleError(
"Handle task running event error, cannot find related workflow instance from cache, will discard this event");
}
Optional<TaskInstance> taskInstanceOptional = workflowExecuteRunnable.getTaskInstance(taskInstanceId);
if (!taskInstanceOptional.isPresent()) {
sendAckToWorker(taskEvent);
throw new TaskEventHandleError(
"Handle running event error, cannot find the taskInstance from cache, will discord this event");
}
TaskInstance taskInstance = taskInstanceOptional.get();
if (taskInstance.getState().isFinished()) {
sendAckToWorker(taskEvent);
throw new TaskEventHandleError(
"Handle task running event error, this task instance is already finished, this event is delay, will discard this event");
}
TaskInstance oldTaskInstance = new TaskInstance();
TaskInstanceUtils.copyTaskInstance(taskInstance, oldTaskInstance);
try {
taskInstance.setStartTime(taskEvent.getStartTime());
taskInstance.setHost(taskEvent.getWorkerAddress());
taskInstance.setPid(taskEvent.getProcessId());
log.info("TaskUpdatePidEventHandler -> {} : pid : {}", taskInstance.getStartTime(), taskEvent.getProcessId());
// TODO 将PID保存到数据库
if (!taskInstanceDao.updateById(taskInstance)) {
throw new TaskEventHandleError("Handle task running event error, update taskInstance to db failed");
}
// TODO ack发送回去
sendAckToWorker(taskEvent);
} catch (Exception ex) {
TaskInstanceUtils.copyTaskInstance(oldTaskInstance, taskInstance);
if (ex instanceof TaskEventHandleError) {
throw ex;
}
throw new TaskEventHandleError("Handle task update pid event error, update taskInstance to db failed", ex);
}
}
注意 : 这是主要核心的代码,其他地方的代码自行修改即可(比如说很多测试类)
如感兴趣,点赞加关注,谢谢!!!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。