From d91afd941ee665928f930f86b99cf96b71976b9a Mon Sep 17 00:00:00 2001 From: yh2388 <178317391@qq.com> Date: Wed, 2 Dec 2020 17:52:25 +0800 Subject: [PATCH] [Fix][Server] Fix clear task execute path is related to master. --- .../master/runner/MasterExecThread.java | 23 ------------- .../worker/runner/TaskExecuteThread.java | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java index e8c9833e0e..368d33d7a4 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java @@ -192,8 +192,6 @@ public class MasterExecThread implements Runnable { processService.updateProcessInstance(processInstance); }finally { taskExecService.shutdown(); - // post handle - postHandle(); } } @@ -381,27 +379,6 @@ public class MasterExecThread implements Runnable { } } - /** - * process post handle - */ - private void postHandle() { - logger.info("develop mode is: {}", CommonUtils.isDevelopMode()); - - if (!CommonUtils.isDevelopMode()) { - // get exec dir - String execLocalPath = org.apache.dolphinscheduler.common.utils.FileUtils - .getProcessExecDir(processInstance.getProcessDefinition().getProjectId(), - processInstance.getProcessDefinitionId(), - processInstance.getId()); - - try { - FileUtils.deleteDirectory(new File(execLocalPath)); - } catch (IOException e) { - logger.error("delete exec dir failed ", e); - } - } - } - /** * submit task to execute * @param taskInstance task instance diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java index fa3e6d2998..d052745d00 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskExecuteThread.java @@ -27,6 +27,7 @@ import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter; import org.apache.dolphinscheduler.common.utils.CommonUtils; import org.apache.dolphinscheduler.common.utils.HadoopUtils; import org.apache.dolphinscheduler.common.utils.LoggerUtils; +import org.apache.dolphinscheduler.common.utils.StringUtils; import org.apache.dolphinscheduler.remote.command.TaskExecuteResponseCommand; import org.apache.dolphinscheduler.server.entity.TaskExecutionContext; import org.apache.dolphinscheduler.server.worker.cache.ResponceCache; @@ -40,6 +41,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -146,8 +148,38 @@ public class TaskExecuteThread implements Runnable { taskExecutionContextCacheManager.removeByTaskInstanceId(taskExecutionContext.getTaskInstanceId()); ResponceCache.get().cache(taskExecutionContext.getTaskInstanceId(),responseCommand.convert2Command(),Event.RESULT); taskCallbackService.sendResult(taskExecutionContext.getTaskInstanceId(), responseCommand.convert2Command()); + clearTaskExecPath(); + } + } + /** + * when task finish, clear execute path. + */ + private void clearTaskExecPath() { + logger.info("develop mode is: {}", CommonUtils.isDevelopMode()); + + if (!CommonUtils.isDevelopMode()) { + // get exec dir + String execLocalPath = taskExecutionContext.getExecutePath(); + + if (StringUtils.isEmpty(execLocalPath)) { + logger.warn("task: {} exec local path is empty.", taskExecutionContext.getTaskName()); + return; + } + + if ("/".equals(execLocalPath)) { + logger.warn("task: {} exec local path is '/', direct deletion is not allowed", taskExecutionContext.getTaskName()); + return; + } + + try { + org.apache.commons.io.FileUtils.deleteDirectory(new File(execLocalPath)); + logger.info("exec local path: {} cleared.", execLocalPath); + } catch (IOException e) { + logger.error("delete exec dir failed : " + e.getMessage(), e); + } } + } /**