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


##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/config/MasterDispatchTimeoutCheckerConfig.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.config;
+
+import java.time.Duration;
+
+import lombok.Data;
+
+/**
+ * Configuration for the master's task dispatch timeout checker.
+ * If enabled, tasks that remain in the dispatch queue longer than {@link 
#maxTaskDispatchDuration} will be marked as failed to prevent indefinite 
queuing.
+ */
+@Data
+public class MasterDispatchTimeoutCheckerConfig {
+
+    /**
+     * Whether to enable the dispatch timeout checking mechanism.
+     */
+    private boolean enabled = false;
+
+    /**
+     * Maximum allowed time for a task to be dispatched to a worker.
+     * Tasks exceeding this duration in the dispatch queue will be failed.
+     * Examples: "2m", "5m", "30m". Defaults to 5 minutes.
+     */
+    private Duration maxTaskDispatchDuration = Duration.ofMinutes(5);

Review Comment:
   ```suggestion
       private Duration maxTaskDispatchDuration;
   ```
   When we don't have a good suggested value, don't set a default value, as 
this can mislead many users.



##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/config/MasterDispatchTimeoutCheckerConfig.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.config;
+
+import java.time.Duration;
+
+import lombok.Data;
+
+/**
+ * Configuration for the master's task dispatch timeout checker.
+ * If enabled, tasks that remain in the dispatch queue longer than {@link 
#maxTaskDispatchDuration} will be marked as failed to prevent indefinite 
queuing.
+ */
+@Data
+public class MasterDispatchTimeoutCheckerConfig {

Review Comment:
   ```suggestion
   public class TaskDispatchPolicy {
   ```



##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/config/MasterDispatchTimeoutCheckerConfig.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.config;
+
+import java.time.Duration;
+
+import lombok.Data;
+
+/**
+ * Configuration for the master's task dispatch timeout checker.
+ * If enabled, tasks that remain in the dispatch queue longer than {@link 
#maxTaskDispatchDuration} will be marked as failed to prevent indefinite 
queuing.
+ */
+@Data
+public class MasterDispatchTimeoutCheckerConfig {
+
+    /**
+     * Whether to enable the dispatch timeout checking mechanism.
+     */
+    private boolean enabled = false;

Review Comment:
   ```suggestion
       private boolean dispatchTimeoutFailedEnabled = false;
   ```



##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/task/lifecycle/event/TaskFatalLifecycleEvent.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.engine.task.lifecycle.event;
+
+import org.apache.dolphinscheduler.server.master.engine.ILifecycleEventType;
+import 
org.apache.dolphinscheduler.server.master.engine.task.lifecycle.AbstractTaskLifecycleEvent;
+import 
org.apache.dolphinscheduler.server.master.engine.task.lifecycle.TaskLifecycleEventType;
+import 
org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable;
+
+import java.util.Date;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+
+@Data
+@Builder
+@AllArgsConstructor
+public class TaskFatalLifecycleEvent extends AbstractTaskLifecycleEvent {
+
+    private final ITaskExecutionRunnable taskExecutionRunnable;
+
+    private final Date endTime;
+
+    @Override
+    public ILifecycleEventType getEventType() {
+        return TaskLifecycleEventType.FATAL;
+    }
+
+    @Override
+    public String toString() {
+        return "TaskFatalLifecycleEvent{" +
+                "task=" + taskExecutionRunnable.getName() +
+                ", endTime=" + endTime +
+                '}';
+    }
+}

Review Comment:
   Please remove this.



##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/task/dispatcher/WorkerGroupDispatcher.java:
##########
@@ -84,23 +95,74 @@ public void run() {
     }
 
     private void doDispatchTask(ITaskExecutionRunnable taskExecutionRunnable) {
+        final int taskInstanceId = taskExecutionRunnable.getId();
+        final TaskExecutionContext taskExecutionContext = 
taskExecutionRunnable.getTaskExecutionContext();
         try {
-            if (!waitingDispatchTaskIds.remove(taskExecutionRunnable.getId())) 
{
+            if (!waitingDispatchTaskIds.remove(taskInstanceId)) {
                 log.info(
                         "The task: {} doesn't exist in 
waitingDispatchTaskIds(it might be paused or killed), will skip dispatch",
-                        taskExecutionRunnable.getId());
+                        taskInstanceId);
                 return;
             }
             taskExecutorClient.dispatch(taskExecutionRunnable);
-        } catch (Exception e) {
+        } catch (TaskDispatchException ex) {

Review Comment:
   ```suggestion
           } catch (Exception ex) {
   ```
   
   Currently, at least in this PR, you can't guarantee that other exceptions 
won't be thrown here, right?



##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/config/MasterConfig.java:
##########
@@ -74,6 +74,13 @@ public class MasterConfig implements Validator {
      */
     private String masterRegistryPath;
 
+    /**
+     * Configuration for the master's task dispatch timeout check mechanism.
+     * This controls whether the system enforces a time limit for dispatching 
tasks to workers,
+     * and if so, how long to wait before marking a task as failed due to 
dispatch timeout.
+     */
+    private MasterDispatchTimeoutCheckerConfig dispatchTimeoutChecker = new 
MasterDispatchTimeoutCheckerConfig();

Review Comment:
   ```suggestion
       private TaskDispatchPolicy taskDispatchPolicy = new TaskDispatchPolicy();
   ```



##########
dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/engine/task/dispatcher/WorkerGroupDispatcherTest.java:
##########
@@ -138,4 +156,285 @@ void dispatch_TaskDispatchFails_RetryLogicWorks() throws 
TaskDispatchException {
                 .untilAsserted(() -> verify(taskExecutorClient, 
times(2)).dispatch(taskExecutionRunnable));
     }
 
+    @Test

Review Comment:
   You should add UT or IT test case to verify the time out check is enabled. 
Your core logic has not been tested.



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

To unsubscribe, e-mail: [email protected]

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

Reply via email to