det101 commented on code in PR #17037:
URL: 
https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1986671596


##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatchManager.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.runner;
+
+import 
org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import 
org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+import org.apache.dolphinscheduler.server.master.runner.queue.DelayEntry;
+import 
org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatchManager implements AutoCloseable {
+
+    @Autowired
+    private ITaskExecutorClient taskExecutorClient;
+
+    @Getter
+    private final ConcurrentHashMap<String, 
WorkerGroupTaskDispatchWaitingQueueLooper> 
workerGroupTaskDispatchWaitingQueueLooperMap;
+    @Getter
+    private final ConcurrentHashMap<String, 
PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>>> 
workerGroupPriorityDelayQueueMap;
+
+    public WorkerGroupTaskDispatchManager() {
+        workerGroupTaskDispatchWaitingQueueLooperMap = new 
ConcurrentHashMap<>();
+        workerGroupPriorityDelayQueueMap = new ConcurrentHashMap<>();
+    }
+
+    /**
+     * Adds a task to the specified worker group queue and starts or wakes up 
the corresponding processing loop.
+     *
+     * @param workerGroup the identifier for the worker group, used to 
distinguish different task queues
+     * @param taskExecutionRunnable an instance of ITaskExecutionRunnable 
representing the task to be executed
+     * @param delayTimeMills the delay time before the task is executed, in 
milliseconds
+     */
+    public void add(String workerGroup, ITaskExecutionRunnable 
taskExecutionRunnable, long delayTimeMills) {
+        PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> 
workerGroupQueue =
+                workerGroupPriorityDelayQueueMap.get(workerGroup);
+        if (workerGroupQueue != null) {
+            workerGroupQueue.add(new DelayEntry<>(delayTimeMills, 
taskExecutionRunnable));
+            log.info("queue size {}", workerGroupQueue.size());
+        } else {
+            log.error("workerGroup {} not found", workerGroup);
+        }
+    }
+
+    /**
+     * Stops a specific worker group's task dispatch waiting queue looper.
+     *
+     * @param workerGroup the identifier for the worker group
+     */
+    public synchronized void stopWorkerGroup(String workerGroup) throws 
Exception {
+        WorkerGroupTaskDispatchWaitingQueueLooper looper =
+                
workerGroupTaskDispatchWaitingQueueLooperMap.remove(workerGroup);
+        PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> 
workerGroupQueue =
+                workerGroupPriorityDelayQueueMap.get(workerGroup);
+        if (workerGroupQueue != null) {
+            workerGroupQueue.clear();
+        }
+        if (looper != null) {
+            looper.close();
+        }
+    }

Review Comment:
   This method is a workergroup deletion logic, which may not be able to handle 
even if it is placed back in the global queue



-- 
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