ruanwenjun commented on code in PR #11464:
URL: https://github.com/apache/dolphinscheduler/pull/11464#discussion_r945415744


##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/consumer/TaskDispatchFailedQueueConsumer.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.server.master.consumer;
+
+import org.apache.dolphinscheduler.common.Constants;
+import org.apache.dolphinscheduler.common.lifecycle.ServerLifeCycleManager;
+import org.apache.dolphinscheduler.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.common.thread.ThreadUtils;
+import org.apache.dolphinscheduler.server.master.config.MasterConfig;
+import org.apache.dolphinscheduler.server.master.metrics.TaskMetrics;
+import 
org.apache.dolphinscheduler.service.exceptions.TaskPriorityQueueException;
+import org.apache.dolphinscheduler.service.queue.TaskPriority;
+import org.apache.dolphinscheduler.service.queue.TaskPriorityQueue;
+import org.apache.dolphinscheduler.service.queue.TaskPriorityQueueImpl;
+
+import java.util.Objects;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Component;
+
+@Component
+public class TaskDispatchFailedQueueConsumer extends BaseDaemonThread {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(TaskDispatchFailedQueueConsumer.class);
+
+    /**
+     * taskPriorityQueue
+     */
+    @Autowired
+    @Qualifier(Constants.TASK_PRIORITY_QUEUE)
+    private TaskPriorityQueue<TaskPriority> taskPriorityQueueImpl;
+
+    /**
+     * taskDispatchFailedQueue
+     */
+    @Autowired
+    @Qualifier(Constants.TASK_DISPATCH_FAILED_QUEUE)
+    private TaskPriorityQueue<TaskPriority> taskDispatchFailedQueueImpl;
+
+    @Autowired
+    private MasterConfig masterConfig;
+
+    private ThreadPoolExecutor retryConsumerThreadPoolExecutor;
+
+    /**
+     * delay time for retries
+     */
+    private static final Long[] TIME_DELAY;
+
+    /**
+     * initialization failure retry delay rule
+     */
+    static {
+        TIME_DELAY = new Long[Constants.DEFAULT_MAX_RETRY_COUNT];
+        for (int i = 0; i < Constants.DEFAULT_MAX_RETRY_COUNT; i++) {
+            int delayTime = (i + 1) * 1000;
+            TIME_DELAY[i] = (long) delayTime;
+        }
+    }
+
+    protected TaskDispatchFailedQueueConsumer() {
+        super("TaskDispatchFailedQueueConsumerThread");
+    }
+
+    @PostConstruct
+    public void init() {
+        this.retryConsumerThreadPoolExecutor = (ThreadPoolExecutor) ThreadUtils
+                
.newDaemonFixedThreadExecutor("TaskDispatchFailedQueueConsumerThread", 
masterConfig.getDispatchTaskNumber());
+        super.start();
+    }
+
+    @Override
+    public void run() {
+        while (!ServerLifeCycleManager.isStopped()) {
+            try {
+                failedRetry();
+            } catch (Exception e) {
+                TaskMetrics.incTaskDispatchError();
+                logger.error("failed task retry error", e);
+            }
+        }
+    }
+
+    public void failedRetry() throws TaskPriorityQueueException {
+        if (taskDispatchFailedQueueImpl.size() > 0) {
+            retryConsumerThreadPoolExecutor.submit(() -> 
dispatchFailedBackToTaskPriorityQueue(masterConfig.getDispatchTaskNumber()));
+        }
+    }

Review Comment:
   This will cause OOM, if the `taskDispatchFailedQueueImpl` is not empty, it 
will submit a lot of task... until the task be trigger
   
   You need to wait the before task finished, and then finish the current loop.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to