You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/12/14 12:48:51 UTC

[GitHub] [dolphinscheduler] github-code-scanning[bot] commented on a diff in pull request #13194: [Feature][Master] Add task caching mechanism to improve the running speed of repetitive tasks

github-code-scanning[bot] commented on code in PR #13194:
URL: https://github.com/apache/dolphinscheduler/pull/13194#discussion_r1048428217


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java:
##########
@@ -319,4 +328,39 @@
         }
         return taskInstance;
     }
+
+    @Override
+    public TaskInstanceRemoveCacheResponse removeTaskInstanceCache(User loginUser, long projectCode,
+                                                                   Integer taskInstanceId) {
+        Result result = new Result();
+
+        Project project = projectMapper.queryByCode(projectCode);
+        projectService.checkProjectAndAuthThrowException(loginUser, project,
+                ApiFuncIdentificationConstant.map.get(INSTANCE_UPDATE));

Review Comment:
   ## Type mismatch on container access
   
   Actual argument type 'String' is incompatible with expected argument type 'ExecuteType'.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/2397)



##########
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/TaskCacheUtils.java:
##########
@@ -0,0 +1,110 @@
+package org.apache.dolphinscheduler.dao.utils;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class TaskCacheUtils {
+
+    final static String MERGE_TAG = "-";
+
+    public static String generateCacheKey(TaskInstance taskInstance, TaskExecutionContext context) {
+        List<String> keyElements = new ArrayList<>();
+        keyElements.add(String.valueOf(taskInstance.getTaskCode()));
+        keyElements.add(String.valueOf(taskInstance.getTaskDefinitionVersion()));
+        keyElements.add(String.valueOf(taskInstance.getIsCache().getCode()));
+        keyElements.add(getTaskInputVarPool(taskInstance, context));
+        String data = StringUtils.join(keyElements, "_");
+        String cacheKey = md5(data);
+        System.out.println("cacheKey: " + cacheKey + ", data: " + data);
+        return cacheKey;
+    }
+
+    public static String generateTagCacheKey(Integer sourceTaskId, String cacheKey) {
+        return sourceTaskId + MERGE_TAG + cacheKey;
+    }
+
+    public static String revertCacheKey(String tagCacheKey) {
+        if (tagCacheKey == null) {
+            return "";
+        }
+        if (tagCacheKey.contains(MERGE_TAG)) {
+            return tagCacheKey.split(MERGE_TAG)[1];
+        } else {
+            return tagCacheKey;
+        }
+    }
+
+    public static String md5(String data) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("MD5");

Review Comment:
   ## Use of a broken or risky cryptographic algorithm
   
   Cryptographic algorithm [MD5](1) is weak and should not be used.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/2396)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org