Browse Source

[Improvement#6438][Worker]remove meaningless DB query (#6440)

org.apache.dolphinscheduler.server.worker.runner.TaskExecuteThread
In the process of task kill, it will query the DB to obtain the task instance object, but this judgment does not make any sense. In fact, the relevant context is already clear, so there is no need to query from DB.
2.0.7-release
Kirs 3 years ago committed by GitHub
parent
commit
ea2a8d26a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/builder/TaskExecutionContextBuilder.java
  2. 16
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java
  3. 14
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/queue/entity/TaskExecutionContext.java

1
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/builder/TaskExecutionContextBuilder.java

@ -61,6 +61,7 @@ public class TaskExecutionContextBuilder {
taskExecutionContext.setResources(taskInstance.getResources()); taskExecutionContext.setResources(taskInstance.getResources());
taskExecutionContext.setDelayTime(taskInstance.getDelayTime()); taskExecutionContext.setDelayTime(taskInstance.getDelayTime());
taskExecutionContext.setVarPool(taskInstance.getVarPool()); taskExecutionContext.setVarPool(taskInstance.getVarPool());
taskExecutionContext.setDryRun(taskInstance.getDryRun());
return this; return this;
} }

16
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java

@ -32,7 +32,6 @@ import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.common.utils.LoggerUtils; import org.apache.dolphinscheduler.common.utils.LoggerUtils;
import org.apache.dolphinscheduler.common.utils.OSUtils; import org.apache.dolphinscheduler.common.utils.OSUtils;
import org.apache.dolphinscheduler.common.utils.RetryerUtils; import org.apache.dolphinscheduler.common.utils.RetryerUtils;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.remote.command.Command; import org.apache.dolphinscheduler.remote.command.Command;
import org.apache.dolphinscheduler.remote.command.TaskExecuteAckCommand; import org.apache.dolphinscheduler.remote.command.TaskExecuteAckCommand;
import org.apache.dolphinscheduler.remote.command.TaskExecuteResponseCommand; import org.apache.dolphinscheduler.remote.command.TaskExecuteResponseCommand;
@ -41,8 +40,6 @@ import org.apache.dolphinscheduler.server.worker.cache.ResponceCache;
import org.apache.dolphinscheduler.server.worker.plugin.TaskPluginManager; import org.apache.dolphinscheduler.server.worker.plugin.TaskPluginManager;
import org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService; import org.apache.dolphinscheduler.server.worker.processor.TaskCallbackService;
import org.apache.dolphinscheduler.service.alert.AlertClientService; import org.apache.dolphinscheduler.service.alert.AlertClientService;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import org.apache.dolphinscheduler.service.process.ProcessService;
import org.apache.dolphinscheduler.service.queue.entity.TaskExecutionContext; import org.apache.dolphinscheduler.service.queue.entity.TaskExecutionContext;
import org.apache.dolphinscheduler.spi.exception.PluginNotFoundException; import org.apache.dolphinscheduler.spi.exception.PluginNotFoundException;
import org.apache.dolphinscheduler.spi.task.AbstractTask; import org.apache.dolphinscheduler.spi.task.AbstractTask;
@ -113,11 +110,6 @@ public class TaskExecuteThread implements Runnable, Delayed {
private TaskPluginManager taskPluginManager; private TaskPluginManager taskPluginManager;
/**
* process database access
*/
protected ProcessService processService;
/** /**
* constructor * constructor
* *
@ -130,7 +122,6 @@ public class TaskExecuteThread implements Runnable, Delayed {
this.taskExecutionContext = taskExecutionContext; this.taskExecutionContext = taskExecutionContext;
this.taskCallbackService = taskCallbackService; this.taskCallbackService = taskCallbackService;
this.alertClientService = alertClientService; this.alertClientService = alertClientService;
this.processService = SpringApplicationContext.getBean(ProcessService.class);
} }
public TaskExecuteThread(TaskExecutionContext taskExecutionContext, public TaskExecuteThread(TaskExecutionContext taskExecutionContext,
@ -141,7 +132,6 @@ public class TaskExecuteThread implements Runnable, Delayed {
this.taskCallbackService = taskCallbackService; this.taskCallbackService = taskCallbackService;
this.alertClientService = alertClientService; this.alertClientService = alertClientService;
this.taskPluginManager = taskPluginManager; this.taskPluginManager = taskPluginManager;
this.processService = SpringApplicationContext.getBean(ProcessService.class);
} }
@Override @Override
@ -167,8 +157,7 @@ public class TaskExecuteThread implements Runnable, Delayed {
} }
logger.info("the task begins to execute. task instance id: {}", taskExecutionContext.getTaskInstanceId()); logger.info("the task begins to execute. task instance id: {}", taskExecutionContext.getTaskInstanceId());
TaskInstance taskInstance = processService.findTaskInstanceById(taskExecutionContext.getTaskInstanceId()); int dryRun = taskExecutionContext.getDryRun();
int dryRun = taskInstance.getDryRun();
// copy hdfs/minio file to local // copy hdfs/minio file to local
if (dryRun == Constants.DRY_RUN_FLAG_NO) { if (dryRun == Constants.DRY_RUN_FLAG_NO) {
downloadResource(taskExecutionContext.getExecutePath(), downloadResource(taskExecutionContext.getExecutePath(),
@ -294,10 +283,7 @@ public class TaskExecuteThread implements Runnable, Delayed {
if (task != null) { if (task != null) {
try { try {
task.cancelApplication(true); task.cancelApplication(true);
TaskInstance taskInstance = processService.findTaskInstanceById(taskExecutionContext.getTaskInstanceId());
if (taskInstance != null) {
ProcessUtils.killYarnJob(taskExecutionContext); ProcessUtils.killYarnJob(taskExecutionContext);
}
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }

14
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/queue/entity/TaskExecutionContext.java

@ -232,6 +232,11 @@ public class TaskExecutionContext implements Serializable {
*/ */
private String varPool; private String varPool;
/**
* dry run flag
*/
private int dryRun;
/** /**
* business param * business param
*/ */
@ -552,6 +557,14 @@ public class TaskExecutionContext implements Serializable {
this.sqoopTaskExecutionContext = sqoopTaskExecutionContext; this.sqoopTaskExecutionContext = sqoopTaskExecutionContext;
} }
public int getDryRun() {
return dryRun;
}
public void setDryRun(int dryRun) {
this.dryRun = dryRun;
}
@Override @Override
public String toString() { public String toString() {
return "TaskExecutionContext{" return "TaskExecutionContext{"
@ -579,6 +592,7 @@ public class TaskExecutionContext implements Serializable {
+ ", projectCode=" + projectCode + ", projectCode=" + projectCode
+ ", taskParams='" + taskParams + '\'' + ", taskParams='" + taskParams + '\''
+ ", envFile='" + envFile + '\'' + ", envFile='" + envFile + '\''
+ ", dryRun='" + dryRun + '\''
+ ", definedParams=" + definedParams + ", definedParams=" + definedParams
+ ", taskAppId='" + taskAppId + '\'' + ", taskAppId='" + taskAppId + '\''
+ ", taskTimeoutStrategy=" + taskTimeoutStrategy + ", taskTimeoutStrategy=" + taskTimeoutStrategy

Loading…
Cancel
Save