You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by "det101 (via GitHub)" <gi...@apache.org> on 2025/03/03 11:39:43 UTC
[PR] [Feature-16260][master]add WorkerGroup queue [dolphinscheduler]
det101 opened a new pull request, #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037
<!--Thanks very much for contributing to Apache DolphinScheduler, we are happy that you want to help us improve DolphinScheduler! -->
## Purpose of the pull request
Simplify the GlobalTaskDispatchWaitingQueue to only handle sorting based on time.
Introduce a new WorkerGroup queue that sorts tasks based on priority and time, with priority being higher than time. Additionally, it is responsible for retrying failed tasks with a delay.
## Brief change log
This change added tests and can be verified as follows:
- *Manually verified the change by testing locally.*
## Pull Request Notice
[Pull Request Notice](https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)
If your pull request contains incompatible change, you should also add it to `docs/docs/en/guide/upgrade/incompatible.md`
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2045883311
##########
dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/queue/TimeBasedTaskExecutionRunnableComparableEntryTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.queue;
+
+import static org.apache.dolphinscheduler.common.thread.ThreadUtils.sleep;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class TimeBasedTaskExecutionRunnableComparableEntryTest {
+
+ private static final long TEST_DELAY_MILLS = 1000L;
+ private final String testData = "testData";
+ private TimeBasedTaskExecutionRunnableComparableEntry<String> entry;
+
+ @BeforeEach
+ public void setUp() {
+ entry = new TimeBasedTaskExecutionRunnableComparableEntry<>(TEST_DELAY_MILLS, testData);
+ }
+
+ @Test
+ public void constructor_NullData_ThrowsNullPointerException() {
+ try {
+ new TimeBasedTaskExecutionRunnableComparableEntry<>(TEST_DELAY_MILLS, null);
+ fail("Expected NullPointerException to be thrown");
+ } catch (NullPointerException e) {
+ assertEquals("data is null", e.getMessage());
+ }
+ }
+
+ @Test
+ public void getDelay_BeforeTriggerTime_ReturnsPositive() {
+ entry = new TimeBasedTaskExecutionRunnableComparableEntry<>(TEST_DELAY_MILLS, testData);
+ sleep(500L);
Review Comment:
Thank you for your suggestions! I have replaced all instances of sleep with Awaitility. Could you please review my changes? 😊
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1992832404
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ThreadCreatingAndDestroyingWorkerGroupListener.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.cluster;
+
+import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.runner.WorkerGroupTaskDispatchManager;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+@Slf4j
+public class ThreadCreatingAndDestroyingWorkerGroupListener implements WorkerGroupChangeNotifier.WorkerGroupListener {
Review Comment:
removed
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2763243560
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [36 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [63.2% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2800815997
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [5 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2808104244
Please retry analysis of this Pull-Request directly on SonarQube Cloud
--
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
Re: [PR] [Feature-16260][master]add WorkerGroup queue [dolphinscheduler]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2694090947
Thanks for opening this pull request! Please check out our contributing guidelines. (https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1987353678
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DispatchWorker.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DispatchWorker extends BaseDaemonThread implements AutoCloseable {
Review Comment:
```suggestion
public class WorkerGroupTaskDispatcher extends BaseDaemonThread implements AutoCloseable {
```
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990643587
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/ComparableEntry.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Objects;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+@Getter
+public class ComparableEntry implements Comparable<ComparableEntry> {
+
+ // Pass it to the workerGroup queue without participating in the comparison
Review Comment:
removed
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatchWaitingQueueLooper.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+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.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class WorkerGroupTaskDispatchWaitingQueueLooper extends BaseDaemonThread implements AutoCloseable {
Review Comment:
removed
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2717589398
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [41 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [60.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026590923
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/TimeBasedTaskExecutionRunnableComparableEntry.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+import java.util.concurrent.Delayed;
+import java.util.concurrent.TimeUnit;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+public class TimeBasedTaskExecutionRunnableComparableEntry<V> implements Delayed {
Review Comment:
Thank you very much for your suggestions! I completely agree with your changes and they do make the code clearer. I will make the changes according to your suggestions.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026597341
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,24 +66,20 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
- log.warn("The TaskInstance {} state is : {}, will not dispatch", taskInstance.getName(), status);
- return;
- }
- taskExecutorClient.dispatch(taskExecutionRunnable);
- } catch (Exception e) {
+ ITaskExecutionRunnable taskExecutionRunnable =
+ globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
+ boolean addTaskSuccess = workerGroupTaskDispatcherManager.addTaskToWorkerGroup(
+ taskExecutionRunnable.getTaskInstance().getWorkerGroup(),
+ taskExecutionRunnable, 0);
+ if (!addTaskSuccess) {
+ log.warn("worker group is deleting or deleted, taskInstance: {}", taskExecutionRunnable.getTaskInstance());
Review Comment:
Thank you very much for your suggestions! I completely agree with your changes and they do make the code clearer. I will make the changes according to your suggestions.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1991223164
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,24 +32,25 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final PriorityBlockingQueue<TimeBasedTaskExecutionRunnableComparableEntry> priorityQueue =
Review Comment:
Okay, this should be the delay queue. I will change the name
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2805014301
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [26 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [68.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.9% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun merged PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2022251192
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/PriorityDelayEntry.java:
##########
@@ -17,25 +17,24 @@
package org.apache.dolphinscheduler.server.master.runner.queue;
-import java.util.concurrent.DelayQueue;
+import java.util.concurrent.Delayed;
-import lombok.SneakyThrows;
+import org.jetbrains.annotations.NotNull;
-public class PriorityDelayQueue<V extends DelayEntry> {
+public class PriorityDelayEntry<V extends Comparable<V>> extends DelayEntry {
Review Comment:
Already restored
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026518865
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
Review Comment:
Since markDispatcherClosing is not a frequently called method, I will add the synchronized keyword to ensure thread safety and address concurrency issues.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026549565
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
+ }
+ }
+
+ /**
+ * Stop all workerGroupTaskDispatchWaitingQueueLooper
+ */
+ @Override
+ public void close() throws Exception {
+ log.info("WorkerGroupTaskDispatcherManager start close");
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ try {
+ entry.getValue().markDispatcherClosing();
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ log.info("WorkerGroupTaskDispatcherManager closed");
+ }
+
+ @Override
+ public void onWorkerGroupAdd(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ for (WorkerGroup workerGroup : workerGroups) {
+ this.addWorkerGroup(workerGroup.getName());
+ }
+ }
+
+ @Override
+ public void onWorkerGroupChange(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ String workerGroupsString = workerGroups.stream()
+ .map(WorkerGroup::getName)
+ .collect(Collectors.joining(", "));
+ log.info("Worker groups: {}", workerGroupsString);
+ }
+
+ @Override
+ public void onWorkerGroupDelete(List<WorkerGroup> workerGroups) {
+ for (WorkerGroup workerGroup : workerGroups) {
+ try {
+ this.deleteWorkerGroup(workerGroup.getName());
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
Review Comment:
Thank you very much for your suggestions! I completely agree with your changes and they do make the code clearer. I will make the changes according to your suggestions.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2789240273
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [29 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [67.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2038998404
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
Review Comment:
To ensure that the entry point for thread creation in WorkerGroupTaskDispatcher is unique and only triggered through addWorkerGroup, special handling is required for the default worker group since it does not trigger an adding event. Moving the logic to check for the existence of a queue when adding a task could complicate the timing of additions and deletions. @ruanwenjun
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2705398371
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [2 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [63.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1986540682
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/ComparableEntry.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Objects;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+@Getter
+public class ComparableEntry implements Comparable<ComparableEntry> {
+
+ // Pass it to the workerGroup queue without participating in the comparison
Review Comment:
```suggestion
// Pass it to the workerGroup queue without participating in the comparison
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/ComparableEntry.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Objects;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+@Getter
+public class ComparableEntry implements Comparable<ComparableEntry> {
Review Comment:
```suggestion
public class TimeBasedTaskExecutionRunnableComparableEntry implements Comparable<ComparableEntry> {
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/ComparableEntry.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Objects;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+@Getter
+public class ComparableEntry implements Comparable<ComparableEntry> {
+
+ // Pass it to the workerGroup queue without participating in the comparison
+ private final long delayTimeMills;
+
+ private final ITaskExecutionRunnable data;
+
+ public ComparableEntry(long delayTimeMills, ITaskExecutionRunnable data) {
+ this.delayTimeMills = delayTimeMills;
+ this.data = checkNotNull(data, "data is null");
+ }
+
+ @Override
+ public int compareTo(@NotNull ComparableEntry other) {
+ int priortyCompareResult = data.compareTo(other.data);
+ if (priortyCompareResult != 0) {
+ return priortyCompareResult;
+ }
+ return Long.compare(delayTimeMills, other.delayTimeMills);
+ }
Review Comment:
```suggestion
public int compareTo(@NotNull ComparableEntry other) {
int delayTimeCompareResult = Long.compare(delayTimeMills, other.delayTimeMills);
if (delayTimeCompareResult != 0) {
return delayTimeCompareResult;
}
return data.compareTo(other.data);
}
```
As discussed at https://github.com/apache/dolphinscheduler/issues/16260#issuecomment-2647236911, this comparation will only compare the delay time.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,6 +49,10 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ @Autowired
+ @Lazy
Review Comment:
Please remove `@Lazy`, this is not a good practice, we should avoid this.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ThreadCreatingAndDestroyingWorkerGroupListener.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.cluster;
+
+import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.runner.WorkerGroupTaskDispatchManager;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+@Slf4j
+public class ThreadCreatingAndDestroyingWorkerGroupListener implements WorkerGroupChangeNotifier.WorkerGroupListener {
Review Comment:
Remove this class, `WorkerGroupTaskDispatchManager` should implements with `WorkerGroupChangeNotifier.WorkerGroupListener`;
##########
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.
Review Comment:
```suggestion
* Adds a task to the specified worker group queue and starts or wakes up the corresponding processing loop.
```
There is no wake up logic.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -57,19 +59,22 @@ public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable ITas
public synchronized void dispatchTaskExecuteRunnableWithDelay(ITaskExecutionRunnable taskExecutionRunnable,
long delayTimeMills) {
waitingTaskInstanceIds.add(taskExecutionRunnable.getTaskInstance().getId());
- priorityDelayQueue.add(new DelayEntry<>(delayTimeMills, taskExecutionRunnable));
+ priorityQueue.add(new ComparableEntry(delayTimeMills, taskExecutionRunnable));
}
/**
- * Consume {@link ITaskExecutionRunnable} from the {@link PriorityDelayQueue}, only the delay time <= 0 can be consumed.
+ * Consume {@link ITaskExecutionRunnable} from the {@link DelayQueue}, only the delay time <= 0 can be consumed.
*/
@SneakyThrows
- public ITaskExecutionRunnable takeTaskExecuteRunnable() {
- ITaskExecutionRunnable taskExecutionRunnable = priorityDelayQueue.take().getData();
+ public ComparableEntry takeTaskExecuteRunnable() {
Review Comment:
```suggestion
public ITaskExecutionRunnable takeTaskExecuteRunnable() {
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatchWaitingQueueLooper.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+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.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class WorkerGroupTaskDispatchWaitingQueueLooper extends BaseDaemonThread implements AutoCloseable {
Review Comment:
Remove this class, directly use DispatchWorker
##########
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:
There will exist a problem, you cannot clear the task, the running task which put into the queue should continue running.
##########
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 {
Review Comment:
```suggestion
public class WorkerGroupTaskDispatcherManager implements AutoCloseable {
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DispatchWorker.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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 lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DispatchWorker {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> workerGroupQueue;
Review Comment:
Please add a `PriorityBasedTaskExecutionRunnableDelayEntry`, this entry should only compare priority rather than delay time.
##########
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;
Review Comment:
```suggestion
private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> workerGroupTaskDispatchWaitingQueueLooperMap;
```
##########
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;
+
Review Comment:
```suggestion
@Getter
private final ConcurrentHashMap<String, PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>>> workerGroupPriorityDelayQueueMap;
```
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2726443969
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [43 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [82.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2020449788
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ MasterThreadFactory.getDefaultSchedulerThreadExecutor().scheduleAtFixedRate(
+ this::checkDeleteDispatchWorkerComplete, 0,
+ CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS, TimeUnit.SECONDS);
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 Boolean add(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.add(taskExecutionRunnable, delayTimeMills);
+ log.info("queue size {}", workerGroupTaskDispatcher.size());
+ return true;
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ return false;
Review Comment:
> > cannot find the workergroup, task will kill.
>
> This conflicts with the existing waiting rules. We should be consistent with the existing logic.
If the name of the worker group is changed, is there a situation where the original logical task will never be completed?
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2019751456
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ MasterThreadFactory.getDefaultSchedulerThreadExecutor().scheduleAtFixedRate(
+ this::checkDeleteDispatchWorkerComplete, 0,
+ CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS, TimeUnit.SECONDS);
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 Boolean add(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.add(taskExecutionRunnable, delayTimeMills);
+ log.info("queue size {}", workerGroupTaskDispatcher.size());
+ return true;
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ return false;
Review Comment:
cannot find the workergroup, task will kill.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2732217190
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [43 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [84.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [Feature-16260][master]add WorkerGroup queue [dolphinscheduler]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1977383087
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/PriorityDelayEntry.java:
##########
@@ -17,25 +17,24 @@
package org.apache.dolphinscheduler.server.master.runner.queue;
-import java.util.concurrent.DelayQueue;
+import java.util.concurrent.Delayed;
-import lombok.SneakyThrows;
+import org.jetbrains.annotations.NotNull;
-public class PriorityDelayQueue<V extends DelayEntry> {
+public class PriorityDelayEntry<V extends Comparable<V>> extends DelayEntry {
Review Comment:
## Inconsistent compareTo
This class declares [compareTo](1) but inherits equals; the two could be inconsistent.
[Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/5158)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2800458441
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [26 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [68.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.9% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2800459677
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2800823403
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2019751399
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,24 +32,25 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final DelayQueue<TimeBasedTaskExecutionRunnableComparableEntry> delayQueue =
+ new DelayQueue<>();
/**
* Submit a {@link ITaskExecutionRunnable} with delay time 0, it will be consumed immediately.
*/
- public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable ITaskExecutionRunnable) {
- dispatchTaskExecuteRunnableWithDelay(ITaskExecutionRunnable, 0);
+ public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable iTaskExecutionRunnable) {
+ dispatchTaskExecuteRunnableWithDelay(iTaskExecutionRunnable, 0);
Review Comment:
Global queue sorted by time, this method has been removed
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2763244126
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [36 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [63.2% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2019764907
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ MasterThreadFactory.getDefaultSchedulerThreadExecutor().scheduleAtFixedRate(
+ this::checkDeleteDispatchWorkerComplete, 0,
+ CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS, TimeUnit.SECONDS);
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 Boolean add(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.add(taskExecutionRunnable, delayTimeMills);
+ log.info("queue size {}", workerGroupTaskDispatcher.size());
+ return true;
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ return false;
Review Comment:
> cannot find the workergroup, task will kill.
This conflicts with the existing waiting rules. We should be consistent with the existing logic.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2000486609
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/TimeBasedTaskExecutionRunnableComparableEntry.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.concurrent.Delayed;
+import java.util.concurrent.TimeUnit;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+public class TimeBasedTaskExecutionRunnableComparableEntry<V> implements Delayed {
Review Comment:
## Inconsistent compareTo
This class declares [compareTo](1) but inherits equals; the two could be inconsistent.
[Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/5161)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1999985612
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,24 +32,25 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final PriorityBlockingQueue<TimeBasedTaskExecutionRunnableComparableEntry> delayQueue =
Review Comment:
@ruanwenjun
Since GlobalQueue only needs to consider the delay time, I have implemented the TimeBasedTaskExecutionRunnableComparableEntry class to only include the getDelay method. The compareTo method defaults to returning 0. Could you please help me review whether this implementation is feasible? If it is feasible, I will proceed with the modification in this way.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1980534651
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,18 +32,19 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final PriorityBlockingQueue<DelayEntry<ITaskExecutionRunnable>> priorityQueue =
Review Comment:
You need to use `DelayQueue` here? Otherwise how to make sure the item will be poll out by a delay time.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/PriorityDelayEntry.java:
##########
@@ -17,25 +17,24 @@
package org.apache.dolphinscheduler.server.master.runner.queue;
-import java.util.concurrent.DelayQueue;
+import java.util.concurrent.Delayed;
-import lombok.SneakyThrows;
+import org.jetbrains.annotations.NotNull;
-public class PriorityDelayQueue<V extends DelayEntry> {
+public class PriorityDelayEntry<V extends Comparable<V>> extends DelayEntry {
Review Comment:
Don't change this class.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupQueueLooper.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.WorkerGroupQueueMap;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+@Slf4j
+public class WorkerGroupQueueLooper extends BaseDaemonThread implements AutoCloseable {
+
+ @Autowired
+ private WorkerGroupQueueMap workerGroupQueueMap;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ private final AtomicBoolean RUNNING_FLAG = new AtomicBoolean(false);
+
+ public WorkerGroupQueueLooper() {
+ super("WorkerGroupQueueLooper");
+ }
+
+ @Override
+ public synchronized void start() {
+ if (!RUNNING_FLAG.compareAndSet(false, true)) {
+ log.error("The WorkerGroupQueueLooper already started, will not start again");
+ return;
+ }
+ log.info("WorkerGroupQueueLooper starting...");
+ super.start();
+ log.info("WorkerGroupQueueLooper started...");
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (RUNNING_FLAG.compareAndSet(true, false)) {
+ log.info("WorkerGroupQueueLooper stopping...");
+ log.info("WorkerGroupQueueLooper stopped...");
+ } else {
+ log.error("WorkerGroupQueueLooper is not started");
+ }
+ }
+
+ @Override
+ public void run() {
+ while (RUNNING_FLAG.get()) {
+ doDispatch();
+ }
Review Comment:
Will make CPU 100%
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/WorkerGroupQueueMap.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.queue;
+
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.DelayQueue;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkerGroupQueueMap {
+
+ private final Map<String, DelayQueue<PriorityDelayEntry<ITaskExecutionRunnable>>> queueMap = new HashMap<>();
Review Comment:
```suggestion
private final Map<String, DelayQueue<PriorityDelayEntry<ITaskExecutionRunnable>>> queueMap = new ConcurrentHashMap<>();
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/WorkflowEngine.java:
##########
@@ -42,6 +43,9 @@ public class WorkflowEngine implements AutoCloseable {
@Autowired
private LogicTaskEngineDelegator logicTaskEngineDelegator;
+ @Autowired
+ private WorkerGroupQueueLooper workerGroupQueueLooper;
Review Comment:
```suggestion
private WorkerGroupTaskDispatchWaitingQueueLooper workerGroupTaskDispatchWatingQueueLooper;
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -57,19 +59,21 @@ public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable ITas
public synchronized void dispatchTaskExecuteRunnableWithDelay(ITaskExecutionRunnable taskExecutionRunnable,
long delayTimeMills) {
waitingTaskInstanceIds.add(taskExecutionRunnable.getTaskInstance().getId());
- priorityDelayQueue.add(new DelayEntry<>(delayTimeMills, taskExecutionRunnable));
+ priorityQueue.add(new DelayEntry<>(delayTimeMills, taskExecutionRunnable));
}
/**
- * Consume {@link ITaskExecutionRunnable} from the {@link PriorityDelayQueue}, only the delay time <= 0 can be consumed.
+ * Consume {@link ITaskExecutionRunnable} from the {@link DelayQueue}, only the delay time <= 0 can be consumed.
*/
@SneakyThrows
- public ITaskExecutionRunnable takeTaskExecuteRunnable() {
- ITaskExecutionRunnable taskExecutionRunnable = priorityDelayQueue.take().getData();
+ public DelayEntry<ITaskExecutionRunnable> takeTaskExecuteRunnable() {
Review Comment:
```suggestion
public ITaskExecutionRunnable takeTaskExecuteRunnable() {
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,25 +64,10 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
- log.warn("The TaskInstance {} state is : {}, will not dispatch", taskInstance.getName(), status);
- return;
- }
- taskExecutorClient.dispatch(taskExecutionRunnable);
- } catch (Exception e) {
- // If dispatch failed, will put the task back to the queue
- // The task will be dispatched after waiting time.
- // the waiting time will increase multiple of times, but will not exceed 60 seconds
- long waitingTimeMills = Math.min(
- taskExecutionRunnable.getTaskExecutionContext().increaseDispatchFailTimes() * 1_000L, 60_000L);
- globalTaskDispatchWaitingQueue.dispatchTaskExecuteRunnableWithDelay(taskExecutionRunnable,
- waitingTimeMills);
- log.error("Dispatch Task: {} failed will retry after: {}/ms", taskInstance.getName(), waitingTimeMills, e);
- }
+ DelayEntry<ITaskExecutionRunnable> delayEntry = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
Review Comment:
Need to add log here.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -38,8 +38,7 @@ public class GlobalTaskDispatchWaitingQueueLooper extends BaseDaemonThread imple
private GlobalTaskDispatchWaitingQueue globalTaskDispatchWaitingQueue;
@Autowired
- private ITaskExecutorClient taskExecutorClient;
-
+ private WorkerGroupQueueMap workerGroupQueueMap;
Review Comment:
```suggestion
private WorkerGroupTaskDispatchWaitingQueues workerGroupTaskDispatchWaitingQueues;
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/DelayEntry.java:
##########
@@ -54,14 +54,6 @@ public long getDelay(@NotNull TimeUnit unit) {
@Override
public int compareTo(@NotNull Delayed o) {
DelayEntry<V> other = (DelayEntry<V>) o;
- int delayTimeMillsCompareResult = Long.compare(delayTimeMills, other.delayTimeMills);
- if (delayTimeMillsCompareResult != 0) {
- return delayTimeMillsCompareResult;
- }
-
- if (data == null || other.data == null) {
- return 0;
- }
Review Comment:
Don't do this kind of change, this class is `DelayEntry` if you remove the compare logic this class cannot work
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2705581899
Please retry analysis of this Pull-Request directly on SonarQube Cloud
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2713097555
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [35 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [60.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1992832063
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DispatchWorker.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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 lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DispatchWorker {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> workerGroupQueue;
Review Comment:
// todo: The current queue is flawed. When a high-priority task fails,
// it will be delayed and will not return to the first or second position.
// Tasks with the same priority will preempt its position.
// If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990509152
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,12 +49,15 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ private WorkerGroupTaskDispatchManager workerGroupTaskDispatchManager;
+
public ClusterManager() {
this.masterClusters = new MasterClusters();
this.workerClusters = new WorkerClusters();
}
- public void start() {
+ public void start(WorkerGroupTaskDispatchManager workerGroupTaskDispatchManager) {
+ this.workerGroupTaskDispatchManager = workerGroupTaskDispatchManager;
Review Comment:
You should add a method to register the `WorkerGroupListener` rather than change the start method, this is too strange.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2808103560
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [19 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [68.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.9% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2732582258
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2705733452
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate failed**
Failed conditions
 [55.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list) (required ≥ 60%)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2705401995
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026592995
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
+ }
+ }
+
+ /**
+ * Stop all workerGroupTaskDispatchWaitingQueueLooper
+ */
+ @Override
+ public void close() throws Exception {
+ log.info("WorkerGroupTaskDispatcherManager start close");
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ try {
+ entry.getValue().markDispatcherClosing();
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ log.info("WorkerGroupTaskDispatcherManager closed");
+ }
+
+ @Override
+ public void onWorkerGroupAdd(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ for (WorkerGroup workerGroup : workerGroups) {
+ this.addWorkerGroup(workerGroup.getName());
+ }
+ }
+
+ @Override
+ public void onWorkerGroupChange(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ String workerGroupsString = workerGroups.stream()
+ .map(WorkerGroup::getName)
+ .collect(Collectors.joining(", "));
+ log.info("Worker groups: {}", workerGroupsString);
+ }
Review Comment:
There is no need to handle the change events here; just log the records. I will change it to log.info("Worker groups: {}", workerGroups);
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2032527116
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicReference<DispatchWorkerStatus> status = new AtomicReference<>(DispatchWorkerStatus.INIT);
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ }
+
+ /**
+ * Adds a task to the worker group queue.
+ *
+ * This method wraps the given task execution object into a priority and delay-based task entry and adds it to the worker group queue.
+ * The task is only added if the current dispatcher status is either STARTED or INIT. If the dispatcher is in any other state,
+ * the task addition will fail, and a warning message will be logged.
+ *
+ * @param taskExecutionRunnable The task execution object to add to the queue, which implements the {@link ITaskExecutionRunnable} interface.
+ * @param delayTimeMills The delay time in milliseconds before the task should be executed.
+ * @return true if the task was successfully added to the queue, false otherwise.
+ */
+ public boolean addTaskToWorkerGroupQueue(ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ if (status.get() == DispatchWorkerStatus.STARTED || status.get() == DispatchWorkerStatus.INIT) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ return true;
+ } else {
+ log.warn("The {} status is {}, task can not add Queue, it will fail", this.getName(), status.get());
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized void start() {
+ if (status.compareAndSet(DispatchWorkerStatus.INIT, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} starting...", this.getName());
+ super.start();
+ log.info("The {} started", this.getName());
+ } else {
+ log.error("The {} status is {}, will not start again", this.getName(), status.get());
+ }
+ }
+
+ public void markDispatcherClosing() {
+ if (status.get() != DispatchWorkerStatus.CLOSED) {
+ status.set(DispatchWorkerStatus.CLOSING);
+ } else {
+ log.warn("The {} is Closed, will not markDispatcherClosing again", this.getName());
+ }
+ }
+
+ public void markDispatcherStart() {
+ if (status.compareAndSet(DispatchWorkerStatus.CLOSING, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} markDispatcherStart...", this.getName());
+ } else {
+ log.warn("The {} status is {}, will not markDispatcherStart", this.getName(), status.get());
+ }
+ }
Review Comment:
> I see. In my design, the dispatcher can still be restarted if it is in the closing state. I just want to make sure I understand correctly—are you saying that once it’s marked as closed, it should no longer support restarting?
@ruanwenjun
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2037664950
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
Review Comment:
Seems meaningless
```suggestion
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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
+ * @return true if the task is successfully added to the queue, false workerGroupTaskDispatcher not found
+ */
+ public synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ return true;
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
Review Comment:
Directly use computeIfAbsent then you can remove the synchronized
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java:
##########
@@ -128,7 +132,9 @@ public void initialized() {
this.masterCoordinator.start();
+ this.clusterManager.registerWorkerGroupListener(this.workerGroupTaskDispatcherManager);
Review Comment:
Meaningless, if we choose to create WorkerGroupDispatcher if not exist in the manager.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2708654945
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [29 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [83.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990723980
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DispatchWorker.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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 lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DispatchWorker {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> workerGroupQueue;
Review Comment:

--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1992838365
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -57,19 +59,22 @@ public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable ITas
public synchronized void dispatchTaskExecuteRunnableWithDelay(ITaskExecutionRunnable taskExecutionRunnable,
long delayTimeMills) {
waitingTaskInstanceIds.add(taskExecutionRunnable.getTaskInstance().getId());
- priorityDelayQueue.add(new DelayEntry<>(delayTimeMills, taskExecutionRunnable));
+ priorityQueue.add(new ComparableEntry(delayTimeMills, taskExecutionRunnable));
}
/**
- * Consume {@link ITaskExecutionRunnable} from the {@link PriorityDelayQueue}, only the delay time <= 0 can be consumed.
+ * Consume {@link ITaskExecutionRunnable} from the {@link DelayQueue}, only the delay time <= 0 can be consumed.
*/
@SneakyThrows
- public ITaskExecutionRunnable takeTaskExecuteRunnable() {
- ITaskExecutionRunnable taskExecutionRunnable = priorityDelayQueue.take().getData();
+ public ComparableEntry takeTaskExecuteRunnable() {
Review Comment:
I have already modified
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1992833123
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,6 +49,10 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ @Autowired
+ @Lazy
Review Comment:
remove @Lazy
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2708761310
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2717477615
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [41 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [60.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2726444070
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [43 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [82.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2708672086
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate failed**
Failed conditions
 [21.1% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list) (required ≥ 60%)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1999985836
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,6 +49,8 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ private WorkerGroupTaskDispatcherManager workerGroupTaskDispatcherManager;
Review Comment:
Thank you very much for your feedback! I will fixe this。
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,24 +32,25 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final PriorityBlockingQueue<TimeBasedTaskExecutionRunnableComparableEntry> delayQueue =
Review Comment:
@ruanwenjun
Since GlobalQueue only needs to consider the delay time, I have implemented the TimeBasedTaskExecutionRunnableComparableEntry class to only include the getDelay method. The compareTo method defaults to returning 0. Could you please help me review whether this implementation is feasible? If it is feasible, I will proceed with the modification in this way.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread implements AutoCloseable {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicBoolean RUNNING_FLAG = new AtomicBoolean(false);
+
+ @Getter
+ private DispatchWorkerStatus status;
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ status = DispatchWorkerStatus.DEFAULT;
+ }
+
+ public void add(ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ }
+
+ public int size() {
+ return workerGroupQueue.size();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (!RUNNING_FLAG.compareAndSet(false, true)) {
+ log.error("The {} already started, will not start again", this.getName());
+ return;
+ }
+ log.info("{} starting...", this.getName());
+ super.start();
+ log.info("{} started...", this.getName());
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (workerGroupQueue.size() == 0) {
+ status = DispatchWorkerStatus.DELETE_SUCCESS;
+ if (RUNNING_FLAG.compareAndSet(true, false)) {
+ log.info("{} stopping...", this.getName());
+ log.info("{} stopped...", this.getName());
+ }
+ } else {
+ log.warn("The {} queue is not empty, will not stop", this.getName());
+ status = DispatchWorkerStatus.DELETING;
+ }
+ }
+
+ @Override
+ public void run() {
+ while (RUNNING_FLAG.get()) {
+ this.dispatch();
+ }
+ }
+
+ public void dispatch() {
Review Comment:
thanks,i will fix this
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DispatchWorkerStatus.java:
##########
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+public enum DispatchWorkerStatus {
+ DEFAULT,
+ DELETE_SUCCESS,
+ DELETING
Review Comment:
Thank you very much for your feedback! I will fixe this。
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,24 +32,25 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final PriorityBlockingQueue<TimeBasedTaskExecutionRunnableComparableEntry> delayQueue =
Review Comment:
Thank you very much for your feedback! I will fixe this。
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ private final ScheduledExecutorService scheduler;
Review Comment:
ok,I will use MasterThreadFactory.getDefaultSchedulerThreadExecutor() instead.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread implements AutoCloseable {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicBoolean RUNNING_FLAG = new AtomicBoolean(false);
+
+ @Getter
+ private DispatchWorkerStatus status;
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ status = DispatchWorkerStatus.DEFAULT;
+ }
+
+ public void add(ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ }
+
+ public int size() {
+ return workerGroupQueue.size();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (!RUNNING_FLAG.compareAndSet(false, true)) {
+ log.error("The {} already started, will not start again", this.getName());
+ return;
+ }
+ log.info("{} starting...", this.getName());
+ super.start();
+ log.info("{} started...", this.getName());
+ }
+
+ @Override
+ public void close() throws Exception {
Review Comment:
Since the close method is overridden, I plan to move the logic to markDispatcherDeleting. Regarding concurrency, I will add synchronized to the close method.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -59,6 +62,10 @@ public void start() {
log.info("ClusterManager started...");
}
+ public void registerWorkerGroupListener(WorkerGroupTaskDispatcherManager workerGroupTaskDispatcherManager) {
+ this.workerGroupTaskDispatcherManager = workerGroupTaskDispatcherManager;
Review Comment:
Thank you very much for your feedback! I will fixe this。
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2001070666
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ MasterThreadFactory.getDefaultSchedulerThreadExecutor().scheduleAtFixedRate(
+ this::checkDeleteDispatchWorkerComplete, 0,
+ CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS, TimeUnit.SECONDS);
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 Boolean add(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.add(taskExecutionRunnable, delayTimeMills);
+ log.info("queue size {}", workerGroupTaskDispatcher.size());
Review Comment:
```suggestion
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,24 +32,25 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final DelayQueue<TimeBasedTaskExecutionRunnableComparableEntry> delayQueue =
+ new DelayQueue<>();
/**
* Submit a {@link ITaskExecutionRunnable} with delay time 0, it will be consumed immediately.
*/
- public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable ITaskExecutionRunnable) {
- dispatchTaskExecuteRunnableWithDelay(ITaskExecutionRunnable, 0);
+ public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable iTaskExecutionRunnable) {
+ dispatchTaskExecuteRunnableWithDelay(iTaskExecutionRunnable, 0);
Review Comment:
Why the delay time is 0 here, if so the `delayQueue` is meaningless.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread implements AutoCloseable {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicBoolean RUNNING_FLAG = new AtomicBoolean(false);
+
+ @Getter
+ private DispatchWorkerStatus status;
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ status = DispatchWorkerStatus.STARTED;
+ }
+
+ public void add(ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ }
+
+ public int size() {
+ return workerGroupQueue.size();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (!RUNNING_FLAG.compareAndSet(false, true)) {
+ log.error("The {} already started, will not start again", this.getName());
+ return;
+ }
+ log.info("{} starting...", this.getName());
+ super.start();
+ log.info("{} started...", this.getName());
+ }
Review Comment:
If a dispatcher closed and then start again, can it start twice? this is a thread!
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ MasterThreadFactory.getDefaultSchedulerThreadExecutor().scheduleAtFixedRate(
+ this::checkDeleteDispatchWorkerComplete, 0,
+ CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS, TimeUnit.SECONDS);
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 Boolean add(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.add(taskExecutionRunnable, delayTimeMills);
+ log.info("queue size {}", workerGroupTaskDispatcher.size());
+ return true;
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ return false;
Review Comment:
If the WorkerGroupTaskDispatcher doens't exist, then the task lifecycle will break? I don't see anywhere deal with the result.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ MasterThreadFactory.getDefaultSchedulerThreadExecutor().scheduleAtFixedRate(
+ this::checkDeleteDispatchWorkerComplete, 0,
+ CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS, TimeUnit.SECONDS);
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 Boolean add(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.add(taskExecutionRunnable, delayTimeMills);
+ log.info("queue size {}", workerGroupTaskDispatcher.size());
+ return true;
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ public synchronized void deleteWorkerGroup(String workerGroup) throws Exception {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.close();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ public synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher looper =
+ dispatchWorkerMap.computeIfAbsent(workerGroup,
+ k -> new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient));
+ looper.start();
+ }
+
+ /**
+ * Stop all workerGroupTaskDispatchWaitingQueueLooper
+ */
+ @Override
+ public void close() throws Exception {
+ log.info("WorkerGroupTaskDispatcherManager start close");
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ try {
+ entry.getValue().close();
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ log.info("WorkerGroupTaskDispatcherManager closed");
+ }
+
+ @Override
+ public void onWorkerGroupAdd(List<WorkerGroup> workerGroups) {
+ for (WorkerGroup workerGroup : workerGroups) {
+ this.addWorkerGroup(workerGroup.getName());
+ }
+ }
+
+ @Override
+ public void onWorkerGroupChange(List<WorkerGroup> workerGroups) {
+ String workerGroupsString = workerGroups.stream()
+ .map(WorkerGroup::getName)
+ .collect(Collectors.joining(", "));
+ log.info("Worker groups: {}", workerGroupsString);
+ }
+
+ @Override
+ public void onWorkerGroupDelete(List<WorkerGroup> workerGroups) {
+ for (WorkerGroup workerGroup : workerGroups) {
+ try {
+ this.deleteWorkerGroup(workerGroup.getName());
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ }
+
+ private void checkDeleteDispatchWorkerComplete() {
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ String workerGroup = entry.getKey();
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = entry.getValue();
+ switch (workerGroupTaskDispatcher.getStatus()) {
+ case CLOSING:
+ try (WorkerGroupTaskDispatcher ignored = workerGroupTaskDispatcher) {
+ log.info("try to delete worker group {}", workerGroup);
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ break;
+ case CLOSED:
+ try (WorkerGroupTaskDispatcher ignored = dispatchWorkerMap.remove(workerGroup)) {
+ log.info("success remove worker group {}", workerGroup);
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ break;
+ default:
+ log.debug("worker group {} status {}", workerGroup, workerGroupTaskDispatcher.getStatus());
+ break;
+ }
+ }
+ }
Review Comment:
Once a dispatcher's status is closed, then it might still exist task in its queue, I don't see any control about this.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2713098821
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [35 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [60.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2034814801
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
+ }
+ }
+
+ /**
+ * Stop all workerGroupTaskDispatchWaitingQueueLooper
+ */
+ @Override
+ public void close() throws Exception {
+ log.info("WorkerGroupTaskDispatcherManager start close");
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ try {
+ entry.getValue().markDispatcherClosing();
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ log.info("WorkerGroupTaskDispatcherManager closed");
Review Comment:
change to
```
entry.getValue().close();
```
WorkerGroupTaskDispatcher will be left as a TODO.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2034810130
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicReference<DispatchWorkerStatus> status = new AtomicReference<>(DispatchWorkerStatus.INIT);
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ }
+
+ /**
+ * Adds a task to the worker group queue.
+ *
+ * This method wraps the given task execution object into a priority and delay-based task entry and adds it to the worker group queue.
+ * The task is only added if the current dispatcher status is either STARTED or INIT. If the dispatcher is in any other state,
+ * the task addition will fail, and a warning message will be logged.
+ *
+ * @param taskExecutionRunnable The task execution object to add to the queue, which implements the {@link ITaskExecutionRunnable} interface.
+ * @param delayTimeMills The delay time in milliseconds before the task should be executed.
+ * @return true if the task was successfully added to the queue, false otherwise.
+ */
+ public boolean addTaskToWorkerGroupQueue(ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ if (status.get() == DispatchWorkerStatus.STARTED || status.get() == DispatchWorkerStatus.INIT) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ return true;
+ } else {
+ log.warn("The {} status is {}, task can not add Queue, it will fail", this.getName(), status.get());
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized void start() {
+ if (status.compareAndSet(DispatchWorkerStatus.INIT, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} starting...", this.getName());
+ super.start();
+ log.info("The {} started", this.getName());
+ } else {
+ log.error("The {} status is {}, will not start again", this.getName(), status.get());
+ }
+ }
+
+ public void markDispatcherClosing() {
+ if (status.get() != DispatchWorkerStatus.CLOSED) {
+ status.set(DispatchWorkerStatus.CLOSING);
+ } else {
+ log.warn("The {} is Closed, will not markDispatcherClosing again", this.getName());
+ }
+ }
+
+ public void markDispatcherStart() {
+ if (status.compareAndSet(DispatchWorkerStatus.CLOSING, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} markDispatcherStart...", this.getName());
+ } else {
+ log.warn("The {} status is {}, will not markDispatcherStart", this.getName(), status.get());
+ }
+ }
Review Comment:
Remove the markstart logic for WorkerGroupTaskDispatcher. Since this scenario is rare and the logic is simplified for now
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1980767143
##########
dolphinscheduler-ui/src/router/modules/ui-setting.ts:
##########
@@ -30,11 +30,11 @@ export default {
children: [
{
path: '',
- name: 'ui-setting',
+ name: 'ui-setting2',
Review Comment:
Please use another PR to do this change.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2024919649
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,24 +66,20 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
Review Comment:
Why you remove this? Are you clear on what this code does? After your removed, the task instance cannot be removed after killed.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,24 +66,20 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
- log.warn("The TaskInstance {} state is : {}, will not dispatch", taskInstance.getName(), status);
- return;
- }
- taskExecutorClient.dispatch(taskExecutionRunnable);
- } catch (Exception e) {
+ ITaskExecutionRunnable taskExecutionRunnable =
+ globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
+ boolean addTaskSuccess = workerGroupTaskDispatcherManager.addTaskToWorkerGroup(
+ taskExecutionRunnable.getTaskInstance().getWorkerGroup(),
+ taskExecutionRunnable, 0);
+ if (!addTaskSuccess) {
+ log.warn("worker group is deleting or deleted, taskInstance: {}", taskExecutionRunnable.getTaskInstance());
Review Comment:
```suggestion
log.warn("Dispatch TaskInstance: {} WorkerGrouTaskDispatcher: {} failed", taskExecutionRunnable.getTaskInstance().getName(), taskExecutionRunnable.getTaskInstance().getWorkerGroup());
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -91,6 +88,7 @@ public void close() throws Exception {
if (RUNNING_FLAG.compareAndSet(true, false)) {
log.info("GlobalTaskDispatchWaitingQueueLooper stopping...");
log.info("GlobalTaskDispatchWaitingQueueLooper stopped...");
+ workerGroupTaskDispatcherManager.close();
Review Comment:
Should before `log.info("GlobalTaskDispatchWaitingQueueLooper stopped...");`
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicReference<DispatchWorkerStatus> status = new AtomicReference<>(DispatchWorkerStatus.INIT);
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ }
+
+ /**
+ * Adds a task to the worker group queue.
+ *
+ * This method wraps the given task execution object into a priority and delay-based task entry and adds it to the worker group queue.
+ * The task is only added if the current dispatcher status is either STARTED or INIT. If the dispatcher is in any other state,
+ * the task addition will fail, and a warning message will be logged.
+ *
+ * @param taskExecutionRunnable The task execution object to add to the queue, which implements the {@link ITaskExecutionRunnable} interface.
+ * @param delayTimeMills The delay time in milliseconds before the task should be executed.
+ * @return true if the task was successfully added to the queue, false otherwise.
+ */
+ public boolean addTaskToWorkerGroupQueue(ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ if (status.get() == DispatchWorkerStatus.STARTED || status.get() == DispatchWorkerStatus.INIT) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ return true;
+ } else {
+ log.warn("The {} status is {}, task can not add Queue, it will fail", this.getName(), status.get());
Review Comment:
```suggestion
log.warn("The WorkerGroupTaskDispatcher: {} status is {}, cannot receive task: {}", this.getName(), status.get(), taskExecutionRunnable.getTaskInstance().getName());
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicReference<DispatchWorkerStatus> status = new AtomicReference<>(DispatchWorkerStatus.INIT);
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ }
+
+ /**
+ * Adds a task to the worker group queue.
+ *
+ * This method wraps the given task execution object into a priority and delay-based task entry and adds it to the worker group queue.
+ * The task is only added if the current dispatcher status is either STARTED or INIT. If the dispatcher is in any other state,
+ * the task addition will fail, and a warning message will be logged.
+ *
+ * @param taskExecutionRunnable The task execution object to add to the queue, which implements the {@link ITaskExecutionRunnable} interface.
+ * @param delayTimeMills The delay time in milliseconds before the task should be executed.
+ * @return true if the task was successfully added to the queue, false otherwise.
+ */
+ public boolean addTaskToWorkerGroupQueue(ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ if (status.get() == DispatchWorkerStatus.STARTED || status.get() == DispatchWorkerStatus.INIT) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ return true;
+ } else {
+ log.warn("The {} status is {}, task can not add Queue, it will fail", this.getName(), status.get());
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized void start() {
+ if (status.compareAndSet(DispatchWorkerStatus.INIT, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} starting...", this.getName());
+ super.start();
+ log.info("The {} started", this.getName());
+ } else {
+ log.error("The {} status is {}, will not start again", this.getName(), status.get());
+ }
+ }
+
+ public void markDispatcherClosing() {
+ if (status.get() != DispatchWorkerStatus.CLOSED) {
+ status.set(DispatchWorkerStatus.CLOSING);
+ } else {
+ log.warn("The {} is Closed, will not markDispatcherClosing again", this.getName());
+ }
+ }
+
+ public void markDispatcherStart() {
+ if (status.compareAndSet(DispatchWorkerStatus.CLOSING, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} markDispatcherStart...", this.getName());
+ } else {
+ log.warn("The {} status is {}, will not markDispatcherStart", this.getName(), status.get());
+ }
+ }
Review Comment:
If the thread has already died, this method cannot restart the dispatcher again.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/TimeBasedTaskExecutionRunnableComparableEntry.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+import java.util.concurrent.Delayed;
+import java.util.concurrent.TimeUnit;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+public class TimeBasedTaskExecutionRunnableComparableEntry<V> implements Delayed {
Review Comment:
Since this component is used for `TaskExecutionRunnable` please don't use generic type here or you should use `<V extends ITaskExecutionRunnbale>`
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
Review Comment:
There will exist concurrency problem, if the dispatcher just close the loop.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
+ }
+ }
+
+ /**
+ * Stop all workerGroupTaskDispatchWaitingQueueLooper
+ */
+ @Override
+ public void close() throws Exception {
+ log.info("WorkerGroupTaskDispatcherManager start close");
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ try {
+ entry.getValue().markDispatcherClosing();
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ log.info("WorkerGroupTaskDispatcherManager closed");
+ }
+
+ @Override
+ public void onWorkerGroupAdd(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ for (WorkerGroup workerGroup : workerGroups) {
+ this.addWorkerGroup(workerGroup.getName());
+ }
+ }
+
+ @Override
+ public void onWorkerGroupChange(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ String workerGroupsString = workerGroups.stream()
+ .map(WorkerGroup::getName)
+ .collect(Collectors.joining(", "));
+ log.info("Worker groups: {}", workerGroupsString);
+ }
Review Comment:
The logic is too strange, and the log is meaningless, no one can unstandard what the log means if he doesn't familiar with the code.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
+ }
+ }
+
+ /**
+ * Stop all workerGroupTaskDispatchWaitingQueueLooper
+ */
+ @Override
+ public void close() throws Exception {
+ log.info("WorkerGroupTaskDispatcherManager start close");
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ try {
+ entry.getValue().markDispatcherClosing();
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ log.info("WorkerGroupTaskDispatcherManager closed");
+ }
+
+ @Override
+ public void onWorkerGroupAdd(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ for (WorkerGroup workerGroup : workerGroups) {
+ this.addWorkerGroup(workerGroup.getName());
+ }
+ }
+
+ @Override
+ public void onWorkerGroupChange(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ String workerGroupsString = workerGroups.stream()
+ .map(WorkerGroup::getName)
+ .collect(Collectors.joining(", "));
+ log.info("Worker groups: {}", workerGroupsString);
+ }
+
+ @Override
+ public void onWorkerGroupDelete(List<WorkerGroup> workerGroups) {
+ for (WorkerGroup workerGroup : workerGroups) {
+ try {
+ this.deleteWorkerGroup(workerGroup.getName());
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
Review Comment:
```suggestion
log.error("Delete worker group: {} from WorkerGroupTaskDispatcherManager error", workerGroup.getName(), e);
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
+ }
+ }
+
+ /**
+ * Stop all workerGroupTaskDispatchWaitingQueueLooper
+ */
+ @Override
+ public void close() throws Exception {
+ log.info("WorkerGroupTaskDispatcherManager start close");
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ try {
+ entry.getValue().markDispatcherClosing();
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ log.info("WorkerGroupTaskDispatcherManager closed");
Review Comment:
In fact you should closed the dispatcher here not just closing.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2041112733
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java:
##########
@@ -128,7 +132,9 @@ public void initialized() {
this.masterCoordinator.start();
+ this.clusterManager.registerWorkerGroupListener(this.workerGroupTaskDispatcherManager);
Review Comment:
Change the logic to dynamically create the workerGroupTaskDispatcher when adding tasks.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2765362237
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [36 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [63.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990660459
##########
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 {
Review Comment:
Modified
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1992836784
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,9 +50,13 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ private final WorkerGroupTaskDispatchManager workerGroupTaskDispatchManager;
+
public ClusterManager() {
this.masterClusters = new MasterClusters();
this.workerClusters = new WorkerClusters();
+ workerGroupTaskDispatchManager = new WorkerGroupTaskDispatchManager();
Review Comment:
Sorry, I missed testing it. I have already modified
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2732221313
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [43 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [84.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2025898976
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,24 +66,20 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
Review Comment:
Thank you for bringing this up. I have moved the status check to the WorkerGroupTaskDispatcher. I believe this change should ensure that the task instance can be removed after being killed. Placing the status check in the global queue could indeed be a better approach. I’m happy to explore that option further if you think it would improve the process.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990707430
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DispatchWorker.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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 lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DispatchWorker {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> workerGroupQueue;
Review Comment:
I have a question. If only priority is compared, then tasks that fail and need to be retried will not have any delay before being retried.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990725819
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,12 +49,15 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ private WorkerGroupTaskDispatchManager workerGroupTaskDispatchManager;
+
public ClusterManager() {
this.masterClusters = new MasterClusters();
this.workerClusters = new WorkerClusters();
}
- public void start() {
+ public void start(WorkerGroupTaskDispatchManager workerGroupTaskDispatchManager) {
+ this.workerGroupTaskDispatchManager = workerGroupTaskDispatchManager;
Review Comment:
i will add registerWorkerGroupListener function
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2717585879
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [41 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [60.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026492567
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicReference<DispatchWorkerStatus> status = new AtomicReference<>(DispatchWorkerStatus.INIT);
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ }
+
+ /**
+ * Adds a task to the worker group queue.
+ *
+ * This method wraps the given task execution object into a priority and delay-based task entry and adds it to the worker group queue.
+ * The task is only added if the current dispatcher status is either STARTED or INIT. If the dispatcher is in any other state,
+ * the task addition will fail, and a warning message will be logged.
+ *
+ * @param taskExecutionRunnable The task execution object to add to the queue, which implements the {@link ITaskExecutionRunnable} interface.
+ * @param delayTimeMills The delay time in milliseconds before the task should be executed.
+ * @return true if the task was successfully added to the queue, false otherwise.
+ */
+ public boolean addTaskToWorkerGroupQueue(ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ if (status.get() == DispatchWorkerStatus.STARTED || status.get() == DispatchWorkerStatus.INIT) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ return true;
+ } else {
+ log.warn("The {} status is {}, task can not add Queue, it will fail", this.getName(), status.get());
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized void start() {
+ if (status.compareAndSet(DispatchWorkerStatus.INIT, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} starting...", this.getName());
+ super.start();
+ log.info("The {} started", this.getName());
+ } else {
+ log.error("The {} status is {}, will not start again", this.getName(), status.get());
+ }
+ }
+
+ public void markDispatcherClosing() {
+ if (status.get() != DispatchWorkerStatus.CLOSED) {
+ status.set(DispatchWorkerStatus.CLOSING);
+ } else {
+ log.warn("The {} is Closed, will not markDispatcherClosing again", this.getName());
+ }
+ }
+
+ public void markDispatcherStart() {
+ if (status.compareAndSet(DispatchWorkerStatus.CLOSING, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} markDispatcherStart...", this.getName());
+ } else {
+ log.warn("The {} status is {}, will not markDispatcherStart", this.getName(), status.get());
+ }
+ }
Review Comment:
I see. In my design, the dispatcher can still be restarted if it is in the closing state. I just want to make sure I understand correctly—are you saying that once it’s marked as closed, it should no longer support restarting?
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026613234
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,24 +66,20 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
Review Comment:
> Thank you for bringing this up. I have moved the status check to the WorkerGroupTaskDispatcher. I believe this change should ensure that the task instance can be removed after being killed. Placing the status check in the global queue could indeed be a better approach. I’m happy to explore that option further if you think it would improve the process.
After some consideration, I have decided to add status checks in the global queue as well.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026600646
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -91,6 +88,7 @@ public void close() throws Exception {
if (RUNNING_FLAG.compareAndSet(true, false)) {
log.info("GlobalTaskDispatchWaitingQueueLooper stopping...");
log.info("GlobalTaskDispatchWaitingQueueLooper stopped...");
+ workerGroupTaskDispatcherManager.close();
Review Comment:
My mistake led to the meaningless log. I will make the changes as suggested.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2705581806
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate failed**
Failed conditions
 [36.7% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list) (required ≥ 60%)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2708654832
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [29 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [83.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2732575069
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [44 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [76.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.5% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2763361463
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [50.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2763361264
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [50.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2765366545
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2708671861
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate failed**
Failed conditions
 [21.1% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list) (required ≥ 60%)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1987346981
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -57,19 +59,22 @@ public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable ITas
public synchronized void dispatchTaskExecuteRunnableWithDelay(ITaskExecutionRunnable taskExecutionRunnable,
long delayTimeMills) {
waitingTaskInstanceIds.add(taskExecutionRunnable.getTaskInstance().getId());
- priorityDelayQueue.add(new DelayEntry<>(delayTimeMills, taskExecutionRunnable));
+ priorityQueue.add(new TimeBasedTaskExecutionRunnableComparableEntry(delayTimeMills, taskExecutionRunnable));
}
/**
- * Consume {@link ITaskExecutionRunnable} from the {@link PriorityDelayQueue}, only the delay time <= 0 can be consumed.
+ * Consume {@link ITaskExecutionRunnable} from the {@link DelayQueue}, only the delay time <= 0 can be consumed.
*/
@SneakyThrows
- public ITaskExecutionRunnable takeTaskExecuteRunnable() {
- ITaskExecutionRunnable taskExecutionRunnable = priorityDelayQueue.take().getData();
+ public TimeBasedTaskExecutionRunnableComparableEntry takeTaskExecuteRunnable() {
Review Comment:
Why not return `ITaskExecutionRunnable`? Why expose `TimeBasedTaskExecutionRunnableComparableEntry` to outside?
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,24 +32,25 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final PriorityBlockingQueue<TimeBasedTaskExecutionRunnableComparableEntry> priorityQueue =
Review Comment:
```suggestion
private final PriorityBlockingQueue<TimeBasedTaskExecutionRunnableComparableEntry> delayQueue =
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,9 +50,13 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ private final WorkerGroupTaskDispatchManager workerGroupTaskDispatchManager;
+
public ClusterManager() {
this.masterClusters = new MasterClusters();
this.workerClusters = new WorkerClusters();
+ workerGroupTaskDispatchManager = new WorkerGroupTaskDispatchManager();
Review Comment:
Can this work? `WorkerGroupTaskDispatchManager` is a spring bean, did you test this?
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2705733837
Please retry analysis of this Pull-Request directly on SonarQube Cloud
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2789237956
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [29 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [67.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990642902
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/ComparableEntry.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Objects;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+@Getter
+public class ComparableEntry implements Comparable<ComparableEntry> {
+
+ // Pass it to the workerGroup queue without participating in the comparison
+ private final long delayTimeMills;
+
+ private final ITaskExecutionRunnable data;
+
+ public ComparableEntry(long delayTimeMills, ITaskExecutionRunnable data) {
+ this.delayTimeMills = delayTimeMills;
+ this.data = checkNotNull(data, "data is null");
+ }
+
+ @Override
+ public int compareTo(@NotNull ComparableEntry other) {
+ int priortyCompareResult = data.compareTo(other.data);
+ if (priortyCompareResult != 0) {
+ return priortyCompareResult;
+ }
+ return Long.compare(delayTimeMills, other.delayTimeMills);
+ }
Review Comment:
Thank you for pointing out the error. It has been changed to a logic consistent with the design
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/ComparableEntry.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.queue;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Objects;
+
+import lombok.Getter;
+
+import org.jetbrains.annotations.NotNull;
+
+@Getter
+public class ComparableEntry implements Comparable<ComparableEntry> {
Review Comment:
This suggestion clarifies the ability to compare and contrast, and the changes have been made.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990525522
##########
dolphinscheduler-ui/src/router/modules/ui-setting.ts:
##########
@@ -30,11 +30,11 @@ export default {
children: [
{
path: '',
- name: 'ui-setting',
+ name: 'ui-setting2',
Review Comment:
Removed modifications
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2712558919
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [34 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [60.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "SbloodyS (via GitHub)" <gi...@apache.org>.
SbloodyS commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2808121477
> If the global queue fails to be distributed to the workergoup queue, the queue will be delayed. If it has been distributed to the workergoup queue, the failure will only be placed in the workergoup's delay queue.
Okay.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2025874408
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,24 +66,20 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
Review Comment:
Thank you for your concern. I have moved the status check to the WorkerGroupTaskDispatcher, which should prevent the task instance from not being removable after being killed. However, I understand that moving it to the global queue for an early check is also a viable option. I appreciate your feedback and will keep this in mind for further improvements.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2034810130
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicReference<DispatchWorkerStatus> status = new AtomicReference<>(DispatchWorkerStatus.INIT);
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ }
+
+ /**
+ * Adds a task to the worker group queue.
+ *
+ * This method wraps the given task execution object into a priority and delay-based task entry and adds it to the worker group queue.
+ * The task is only added if the current dispatcher status is either STARTED or INIT. If the dispatcher is in any other state,
+ * the task addition will fail, and a warning message will be logged.
+ *
+ * @param taskExecutionRunnable The task execution object to add to the queue, which implements the {@link ITaskExecutionRunnable} interface.
+ * @param delayTimeMills The delay time in milliseconds before the task should be executed.
+ * @return true if the task was successfully added to the queue, false otherwise.
+ */
+ public boolean addTaskToWorkerGroupQueue(ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ if (status.get() == DispatchWorkerStatus.STARTED || status.get() == DispatchWorkerStatus.INIT) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ return true;
+ } else {
+ log.warn("The {} status is {}, task can not add Queue, it will fail", this.getName(), status.get());
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized void start() {
+ if (status.compareAndSet(DispatchWorkerStatus.INIT, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} starting...", this.getName());
+ super.start();
+ log.info("The {} started", this.getName());
+ } else {
+ log.error("The {} status is {}, will not start again", this.getName(), status.get());
+ }
+ }
+
+ public void markDispatcherClosing() {
+ if (status.get() != DispatchWorkerStatus.CLOSED) {
+ status.set(DispatchWorkerStatus.CLOSING);
+ } else {
+ log.warn("The {} is Closed, will not markDispatcherClosing again", this.getName());
+ }
+ }
+
+ public void markDispatcherStart() {
+ if (status.compareAndSet(DispatchWorkerStatus.CLOSING, DispatchWorkerStatus.STARTED)) {
+ log.info("The {} markDispatcherStart...", this.getName());
+ } else {
+ log.warn("The {} status is {}, will not markDispatcherStart", this.getName(), status.get());
+ }
+ }
Review Comment:
Remove the close logic for WorkerGroupTaskDispatcher. Since this scenario is rare and the logic is simplified for now, it will be left as a TODO.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2805015066
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [26 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [68.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.9% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2044414425
##########
dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/queue/TimeBasedTaskExecutionRunnableComparableEntryTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.queue;
+
+import static org.apache.dolphinscheduler.common.thread.ThreadUtils.sleep;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class TimeBasedTaskExecutionRunnableComparableEntryTest {
+
+ private static final long TEST_DELAY_MILLS = 1000L;
+ private final String testData = "testData";
+ private TimeBasedTaskExecutionRunnableComparableEntry<String> entry;
+
+ @BeforeEach
+ public void setUp() {
+ entry = new TimeBasedTaskExecutionRunnableComparableEntry<>(TEST_DELAY_MILLS, testData);
+ }
+
+ @Test
+ public void constructor_NullData_ThrowsNullPointerException() {
+ try {
+ new TimeBasedTaskExecutionRunnableComparableEntry<>(TEST_DELAY_MILLS, null);
+ fail("Expected NullPointerException to be thrown");
+ } catch (NullPointerException e) {
+ assertEquals("data is null", e.getMessage());
+ }
+ }
+
+ @Test
+ public void getDelay_BeforeTriggerTime_ReturnsPositive() {
+ entry = new TimeBasedTaskExecutionRunnableComparableEntry<>(TEST_DELAY_MILLS, testData);
+ sleep(500L);
Review Comment:
It's better to use `Awaitility`, rather than sleep
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2034809473
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,24 +66,20 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
Review Comment:
Remove the close logic for WorkerGroupTaskDispatcher. Since this scenario is rare and the logic is simplified for now, it will be left as a TODO.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2808116849
> I agree with this implementation, I just have some questions. After reviewing the code, I found that this PR is to put the failed tasks in the delayed queue and wait for a certain period of time before resubmitting, instead of actually dividing them into multiple queues according to the worker group as stated in the title, is that right? @det101
If the global queue fails to be distributed to the workergoup queue, the queue will be delayed. If it has been distributed to the workergoup queue, the failure will only be placed in the workergoup's delay 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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2039007302
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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
+ * @return true if the task is successfully added to the queue, false workerGroupTaskDispatcher not found
+ */
+ public synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ return true;
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
Review Comment:
To ensure that the entry point for thread creation in WorkerGroupTaskDispatcher is unique and only triggered through addWorkerGroup, special handling is required for the default worker group since it does not trigger an adding event. Moving the logic to check for the existence of a queue when adding a task could complicate the timing of additions and deletions.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1998123165
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DispatchWorkerStatus.java:
##########
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+public enum DispatchWorkerStatus {
+ DEFAULT,
+ DELETE_SUCCESS,
+ DELETING
Review Comment:
```suggestion
STARTED,
CLOSING,
CLOSED,
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ private final ScheduledExecutorService scheduler;
Review Comment:
You cannot control this threadpool, so don't maintain this.
```suggestion
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/PriorityAndDelayBasedTaskEntry.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.queue;
+
+import java.util.concurrent.Delayed;
+import java.util.concurrent.TimeUnit;
+
+import org.jetbrains.annotations.NotNull;
+
+public class PriorityAndDelayBasedTaskEntry<V extends Comparable<V>> extends DelayEntry<V> {
Review Comment:
```suggestion
public class PriorityDelayTaskEntry<V extends Comparable<V>> extends DelayEntry<V> {
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread implements AutoCloseable {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicBoolean RUNNING_FLAG = new AtomicBoolean(false);
+
+ @Getter
+ private DispatchWorkerStatus status;
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ status = DispatchWorkerStatus.DEFAULT;
+ }
+
+ public void add(ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ }
+
+ public int size() {
+ return workerGroupQueue.size();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (!RUNNING_FLAG.compareAndSet(false, true)) {
+ log.error("The {} already started, will not start again", this.getName());
+ return;
+ }
+ log.info("{} starting...", this.getName());
+ super.start();
+ log.info("{} started...", this.getName());
+ }
+
+ @Override
+ public void close() throws Exception {
Review Comment:
You need to do concurrency control in this class.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -59,6 +62,10 @@ public void start() {
log.info("ClusterManager started...");
}
+ public void registerWorkerGroupListener(WorkerGroupTaskDispatcherManager workerGroupTaskDispatcherManager) {
+ this.workerGroupTaskDispatcherManager = workerGroupTaskDispatcherManager;
Review Comment:
```suggestion
this.workerGroupChangeNotifier.subscribeWorkerGroupsChange(workerGroupTaskDispatcherManager);
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,6 +49,8 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ private WorkerGroupTaskDispatcherManager workerGroupTaskDispatcherManager;
Review Comment:
```suggestion
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/ClusterManager.java:
##########
@@ -48,6 +49,8 @@ public class ClusterManager {
@Autowired
private RegistryClient registryClient;
+ private WorkerGroupTaskDispatcherManager workerGroupTaskDispatcherManager;
Review Comment:
Use a list here or we can directly remove this line.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread implements AutoCloseable {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicBoolean RUNNING_FLAG = new AtomicBoolean(false);
+
+ @Getter
+ private DispatchWorkerStatus status;
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ status = DispatchWorkerStatus.DEFAULT;
+ }
+
+ public void add(ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ }
+
+ public int size() {
+ return workerGroupQueue.size();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (!RUNNING_FLAG.compareAndSet(false, true)) {
+ log.error("The {} already started, will not start again", this.getName());
+ return;
+ }
+ log.info("{} starting...", this.getName());
+ super.start();
+ log.info("{} started...", this.getName());
+ }
+
+ @Override
+ public void close() throws Exception {
Review Comment:
```suggestion
public void markDispatcherDeleting() throws Exception {
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread implements AutoCloseable {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicBoolean RUNNING_FLAG = new AtomicBoolean(false);
+
+ @Getter
+ private DispatchWorkerStatus status;
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ status = DispatchWorkerStatus.DEFAULT;
+ }
+
+ public void add(ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ }
+
+ public int size() {
+ return workerGroupQueue.size();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (!RUNNING_FLAG.compareAndSet(false, true)) {
+ log.error("The {} already started, will not start again", this.getName());
+ return;
+ }
+ log.info("{} starting...", this.getName());
+ super.start();
+ log.info("{} started...", this.getName());
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (workerGroupQueue.size() == 0) {
+ status = DispatchWorkerStatus.DELETE_SUCCESS;
+ if (RUNNING_FLAG.compareAndSet(true, false)) {
+ log.info("{} stopping...", this.getName());
+ log.info("{} stopped...", this.getName());
+ }
+ } else {
+ log.warn("The {} queue is not empty, will not stop", this.getName());
+ status = DispatchWorkerStatus.DELETING;
+ }
+ }
+
+ @Override
+ public void run() {
+ while (RUNNING_FLAG.get()) {
+ this.dispatch();
+ }
+ }
+
+ public void dispatch() {
Review Comment:
```suggestion
private void dispatch() {
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcher.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.PriorityAndDelayBasedTaskEntry;
+import org.apache.dolphinscheduler.server.master.runner.queue.PriorityDelayQueue;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * WorkerGroupTaskDispatcher is responsible for dispatching tasks from the task queue.
+ * The main responsibilities include:
+ * 1. Continuously fetching tasks from the {@link PriorityDelayQueue} for dispatch.
+ * 2. Re-queuing tasks that fail to dispatch according to retry logic.
+ * 3. Ensuring thread safety and correct state transitions during task processing.
+ */
+@Slf4j
+public class WorkerGroupTaskDispatcher extends BaseDaemonThread implements AutoCloseable {
+
+ private final ITaskExecutorClient taskExecutorClient;
+
+ // todo: The current queue is flawed. When a high-priority task fails,
+ // it will be delayed and will not return to the first or second position.
+ // Tasks with the same priority will preempt its position.
+ // If it needs to be placed at the front of the queue, the queue needs to be re-implemented.
+ private final PriorityDelayQueue<PriorityAndDelayBasedTaskEntry> workerGroupQueue;
+
+ private final AtomicBoolean RUNNING_FLAG = new AtomicBoolean(false);
+
+ @Getter
+ private DispatchWorkerStatus status;
+
+ public WorkerGroupTaskDispatcher(String workerGroupName, ITaskExecutorClient taskExecutorClient) {
+ super("WorkerGroupTaskDispatcher-" + workerGroupName);
+ this.taskExecutorClient = taskExecutorClient;
+ this.workerGroupQueue = new PriorityDelayQueue<>();
+ status = DispatchWorkerStatus.DEFAULT;
+ }
+
+ public void add(ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ workerGroupQueue.add(new PriorityAndDelayBasedTaskEntry(delayTimeMills, taskExecutionRunnable));
+ }
+
+ public int size() {
+ return workerGroupQueue.size();
+ }
+
+ @Override
+ public synchronized void start() {
+ if (!RUNNING_FLAG.compareAndSet(false, true)) {
+ log.error("The {} already started, will not start again", this.getName());
+ return;
+ }
+ log.info("{} starting...", this.getName());
+ super.start();
+ log.info("{} started...", this.getName());
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (workerGroupQueue.size() == 0) {
+ status = DispatchWorkerStatus.DELETE_SUCCESS;
+ if (RUNNING_FLAG.compareAndSet(true, false)) {
+ log.info("{} stopping...", this.getName());
+ log.info("{} stopped...", this.getName());
+ }
+ } else {
+ log.warn("The {} queue is not empty, will not stop", this.getName());
+ status = DispatchWorkerStatus.DELETING;
+ }
+ }
+
+ @Override
+ public void run() {
+ while (RUNNING_FLAG.get()) {
+ this.dispatch();
+ }
+ }
+
+ public void dispatch() {
Review Comment:
This method should not exposed to outside.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -31,24 +32,25 @@
/**
* The class is used to store {@link ITaskExecutionRunnable} which needs to be dispatched. The {@link ITaskExecutionRunnable}
- * will be stored in {@link PriorityDelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
+ * will be stored in {@link DelayQueue}, if the {@link ITaskExecutionRunnable}'s delay time is 0, then it will be
* consumed by {@link GlobalTaskDispatchWaitingQueueLooper}.
* <p>
- * The order of {@link ITaskExecutionRunnable} in the {@link PriorityDelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
+ * The order of {@link ITaskExecutionRunnable} in the {@link DelayQueue} is determined by {@link ITaskExecutionRunnable#compareTo}.
*/
@Slf4j
@Component
public class GlobalTaskDispatchWaitingQueue {
private final Set<Integer> waitingTaskInstanceIds = ConcurrentHashMap.newKeySet();
- private final PriorityDelayQueue<DelayEntry<ITaskExecutionRunnable>> priorityDelayQueue =
- new PriorityDelayQueue<>();
+
+ private final PriorityBlockingQueue<TimeBasedTaskExecutionRunnableComparableEntry> delayQueue =
Review Comment:
We should use DelayQueue here.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2708282535
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [19 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [76.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2708282598
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [19 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [76.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2708761009
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate failed**
Failed conditions
 [21.1% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list) (required ≥ 60%)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2712558863
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [34 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [60.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r1990715549
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueue.java:
##########
@@ -57,19 +59,22 @@ public synchronized void dispatchTaskExecuteRunnable(ITaskExecutionRunnable ITas
public synchronized void dispatchTaskExecuteRunnableWithDelay(ITaskExecutionRunnable taskExecutionRunnable,
long delayTimeMills) {
waitingTaskInstanceIds.add(taskExecutionRunnable.getTaskInstance().getId());
- priorityDelayQueue.add(new DelayEntry<>(delayTimeMills, taskExecutionRunnable));
+ priorityQueue.add(new TimeBasedTaskExecutionRunnableComparableEntry(delayTimeMills, taskExecutionRunnable));
}
/**
- * Consume {@link ITaskExecutionRunnable} from the {@link PriorityDelayQueue}, only the delay time <= 0 can be consumed.
+ * Consume {@link ITaskExecutionRunnable} from the {@link DelayQueue}, only the delay time <= 0 can be consumed.
*/
@SneakyThrows
- public ITaskExecutionRunnable takeTaskExecuteRunnable() {
- ITaskExecutionRunnable taskExecutionRunnable = priorityDelayQueue.take().getData();
+ public TimeBasedTaskExecutionRunnableComparableEntry takeTaskExecuteRunnable() {
Review Comment:
The previous global queue data retrieval solution was incorrect, but it has now been modified.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2717473782
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [41 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [60.8% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2020490583
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+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.utils.MasterThreadFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ private static final long CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS = 5;
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ MasterThreadFactory.getDefaultSchedulerThreadExecutor().scheduleAtFixedRate(
+ this::checkDeleteDispatchWorkerComplete, 0,
+ CHECK_DELETE_DISPATCH_WORKER_PERIOD_SECONDS, TimeUnit.SECONDS);
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 Boolean add(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable, long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.add(taskExecutionRunnable, delayTimeMills);
+ log.info("queue size {}", workerGroupTaskDispatcher.size());
+ return true;
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ return false;
Review Comment:
> > cannot find the workergroup, task will kill.
>
> This conflicts with the existing waiting rules. We should be consistent with the existing logic.
Already changed to existing logic
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2765259912
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [36 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [63.2% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#issuecomment-2765259348
## [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037) **Quality Gate passed**
Issues
 [36 New issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=17037&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [63.2% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_coverage&view=list)
 [1.7% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=17037&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=17037)
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2025874408
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooper.java:
##########
@@ -65,24 +66,20 @@ public void run() {
}
void doDispatch() {
- final ITaskExecutionRunnable taskExecutionRunnable = globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable();
- final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance();
- try {
- final TaskExecutionStatus status = taskInstance.getState();
- if (status != TaskExecutionStatus.SUBMITTED_SUCCESS && status != TaskExecutionStatus.DELAY_EXECUTION) {
Review Comment:
Thank you for your concern. I have moved the status check to the WorkerGroupTaskDispatcher, which should prevent the task instance from not being removable after being killed. However, I understand that moving it to the global queue for an early check is also a viable option. I appreciate your feedback and will keep this in mind for further improvements.
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2026592995
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkerGroupTaskDispatcherManager.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.dao.entity.WorkerGroup;
+import org.apache.dolphinscheduler.dao.utils.WorkerGroupUtils;
+import org.apache.dolphinscheduler.server.master.cluster.WorkerGroupChangeNotifier;
+import org.apache.dolphinscheduler.server.master.engine.task.client.ITaskExecutorClient;
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * WorkerGroupTaskDispatcherManager is responsible for managing the task dispatching for worker groups.
+ * It maintains a mapping of worker groups to their task dispatchers and priority delay queues,
+ * and supports adding tasks, starting and stopping worker groups, as well as cleaning up resources upon shutdown.
+ */
+@Component
+@Slf4j
+public class WorkerGroupTaskDispatcherManager implements AutoCloseable, WorkerGroupChangeNotifier.WorkerGroupListener {
+
+ @Autowired
+ private ITaskExecutorClient taskExecutorClient;
+
+ @Getter
+ private final ConcurrentHashMap<String, WorkerGroupTaskDispatcher> dispatchWorkerMap;
+
+ public WorkerGroupTaskDispatcherManager() {
+ dispatchWorkerMap = new ConcurrentHashMap<>();
+ }
+
+ @PostConstruct
+ public void init() {
+ this.addWorkerGroup(WorkerGroupUtils.getDefaultWorkerGroup());
+ }
+
+ /**
+ * 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 synchronized boolean addTaskToWorkerGroup(String workerGroup, ITaskExecutionRunnable taskExecutionRunnable,
+ long delayTimeMills) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ if (workerGroupTaskDispatcher.checkCloseDispatchWorkerComplete()) {
+ dispatchWorkerMap.remove(workerGroup);
+ return false;
+ }
+ return workerGroupTaskDispatcher.addTaskToWorkerGroupQueue(taskExecutionRunnable, delayTimeMills);
+ } else {
+ log.error("workerGroupTaskDispatcher {} not found, will set task {} fail",
+ workerGroup, taskExecutionRunnable.getTaskInstance().getId());
+ }
+ return false;
+ }
+
+ /**
+ * Stops a specific worker group's task dispatch waiting queue looper.
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void deleteWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher != null) {
+ workerGroupTaskDispatcher.markDispatcherClosing();
+ } else {
+ log.warn("workerGroupTaskDispatcher {} not found", workerGroup);
+ }
+ }
+
+ /**
+ * add workerGroup
+ *
+ * @param workerGroup the identifier for the worker group
+ */
+ private synchronized void addWorkerGroup(String workerGroup) {
+ WorkerGroupTaskDispatcher workerGroupTaskDispatcher = dispatchWorkerMap.get(workerGroup);
+ if (workerGroupTaskDispatcher == null) {
+ workerGroupTaskDispatcher = new WorkerGroupTaskDispatcher(workerGroup, taskExecutorClient);
+ dispatchWorkerMap.put(workerGroup, workerGroupTaskDispatcher);
+ workerGroupTaskDispatcher.start();
+ } else {
+ workerGroupTaskDispatcher.markDispatcherStart();
+ }
+ }
+
+ /**
+ * Stop all workerGroupTaskDispatchWaitingQueueLooper
+ */
+ @Override
+ public void close() throws Exception {
+ log.info("WorkerGroupTaskDispatcherManager start close");
+ for (Map.Entry<String, WorkerGroupTaskDispatcher> entry : dispatchWorkerMap.entrySet()) {
+ try {
+ entry.getValue().markDispatcherClosing();
+ } catch (Exception e) {
+ log.error("stop worker group error", e);
+ }
+ }
+ log.info("WorkerGroupTaskDispatcherManager closed");
+ }
+
+ @Override
+ public void onWorkerGroupAdd(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ for (WorkerGroup workerGroup : workerGroups) {
+ this.addWorkerGroup(workerGroup.getName());
+ }
+ }
+
+ @Override
+ public void onWorkerGroupChange(List<WorkerGroup> workerGroups) {
+ this.checkAndRemoveClosedDispatchWorker();
+ String workerGroupsString = workerGroups.stream()
+ .map(WorkerGroup::getName)
+ .collect(Collectors.joining(", "));
+ log.info("Worker groups: {}", workerGroupsString);
+ }
Review Comment:
There is no need to handle the change events here; just log the records. I will change it to log.info("on change worker groups: {}", workerGroups);
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2022242727
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/DispatchWorker.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.common.thread.BaseDaemonThread;
+import org.apache.dolphinscheduler.dao.entity.TaskInstance;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
+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.atomic.AtomicBoolean;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class DispatchWorker extends BaseDaemonThread implements AutoCloseable {
Review Comment:
The modification has been completed
--
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
Re: [PR] [DSIP-55][Master] Separate the waiting dispatched task into different queue by worker group [dolphinscheduler]
Posted by "det101 (via GitHub)" <gi...@apache.org>.
det101 commented on code in PR #17037:
URL: https://github.com/apache/dolphinscheduler/pull/17037#discussion_r2022243665
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/queue/WorkerGroupQueueMap.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.queue;
+
+import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.DelayQueue;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component
+public class WorkerGroupQueueMap {
+
+ private final Map<String, DelayQueue<PriorityDelayEntry<ITaskExecutionRunnable>>> queueMap = new HashMap<>();
Review Comment:
The modification has been completed
--
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