-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[Fix-18338] check task if it's waiting for TaskGroup slot when pause/kill #18344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eye-gu
wants to merge
4
commits into
apache:dev
Choose a base branch
from
eye-gu:fix-18338-pause-task-wait-wotk-group
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
...dolphinscheduler/server/master/engine/task/statemachine/TaskSubmittedStateActionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| /* | ||
| * 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.statemachine; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import org.apache.dolphinscheduler.dao.entity.TaskInstance; | ||
| import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; | ||
| import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; | ||
| import org.apache.dolphinscheduler.server.master.engine.ITaskGroupCoordinator; | ||
| import org.apache.dolphinscheduler.server.master.engine.WorkflowEventBus; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.dispatcher.WorkerGroupDispatcherCoordinator; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.execution.ITaskExecution; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskKillLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskKilledLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskPauseLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskPausedLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.workflow.execution.IWorkflowExecution; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.mockito.junit.jupiter.MockitoSettings; | ||
| import org.mockito.quality.Strictness; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| @MockitoSettings(strictness = Strictness.LENIENT) | ||
| class TaskSubmittedStateActionTest { | ||
|
|
||
| @InjectMocks | ||
| private TaskSubmittedStateAction taskSubmittedStateAction; | ||
|
|
||
| @Mock | ||
| private WorkerGroupDispatcherCoordinator workerGroupDispatcherCoordinator; | ||
|
|
||
| @Mock | ||
| private TaskInstanceDao taskInstanceDao; | ||
|
|
||
| @Mock | ||
| private ITaskGroupCoordinator taskGroupCoordinator; | ||
|
|
||
| @Mock | ||
| private IWorkflowExecution workflowExecution; | ||
|
|
||
| @Mock | ||
| private ITaskExecution taskExecution; | ||
|
|
||
| @Mock | ||
| private WorkflowEventBus workflowEventBus; | ||
|
|
||
| private TaskInstance taskInstance; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| taskInstance = new TaskInstance(); | ||
| taskInstance.setState(TaskExecutionStatus.SUBMITTED_SUCCESS); | ||
| taskInstance.setName("testTask"); | ||
| taskInstance.setId(1); | ||
|
|
||
| when(taskExecution.getTaskInstance()).thenReturn(taskInstance); | ||
| when(taskExecution.getWorkflowEventBus()).thenReturn(workflowEventBus); | ||
| when(taskExecution.getName()).thenReturn("testTask"); | ||
| when(taskExecution.getId()).thenReturn(1); | ||
| } | ||
|
|
||
| @Test | ||
| void onPauseEvent_taskWaitingForTaskGroupSlot_shouldPauseDirectly() { | ||
| // Task not in dispatch queue | ||
| when(workerGroupDispatcherCoordinator.removeTask(taskExecution)).thenReturn(false); | ||
| // Task is waiting for TaskGroup slot | ||
| when(taskGroupCoordinator.isTaskWaitingForTaskGroupSlot(taskInstance)).thenReturn(true); | ||
|
|
||
| taskSubmittedStateAction.onPauseEvent(workflowExecution, taskExecution, null); | ||
|
|
||
| verify(taskGroupCoordinator).releaseTaskGroupSlot(taskInstance); | ||
| verify(workflowEventBus).publish(any(TaskPausedLifecycleEvent.class)); | ||
| // Should NOT publish a delayed TaskPauseLifecycleEvent | ||
| verify(workflowEventBus, never()).publish(any(TaskPauseLifecycleEvent.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void onPauseEvent_taskInDispatchQueue_shouldPauseDirectly() { | ||
| // Task is in dispatch queue | ||
| when(workerGroupDispatcherCoordinator.removeTask(taskExecution)).thenReturn(true); | ||
|
|
||
| taskSubmittedStateAction.onPauseEvent(workflowExecution, taskExecution, null); | ||
|
|
||
| verify(workflowEventBus).publish(any(TaskPausedLifecycleEvent.class)); | ||
| // Should NOT check TaskGroup since task was removed from dispatch queue | ||
| verify(taskGroupCoordinator, never()).isTaskWaitingForTaskGroupSlot(any()); | ||
| } | ||
|
|
||
| @Test | ||
| void onPauseEvent_taskNotInDispatchQueueAndNotWaiting_shouldRetryAfter5s() { | ||
| // Task not in dispatch queue | ||
| when(workerGroupDispatcherCoordinator.removeTask(taskExecution)).thenReturn(false); | ||
| // Task is NOT waiting for TaskGroup slot | ||
| when(taskGroupCoordinator.isTaskWaitingForTaskGroupSlot(taskInstance)).thenReturn(false); | ||
|
|
||
| taskSubmittedStateAction.onPauseEvent(workflowExecution, taskExecution, null); | ||
|
|
||
| verify(taskGroupCoordinator, never()).releaseTaskGroupSlot(any()); | ||
| // Should publish a delayed TaskPauseLifecycleEvent (retry after 5s) | ||
| verify(workflowEventBus).publish(any(TaskPauseLifecycleEvent.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void onKillEvent_taskWaitingForTaskGroupSlot_shouldKillDirectly() { | ||
| // Task not in dispatch queue | ||
| when(workerGroupDispatcherCoordinator.removeTask(taskExecution)).thenReturn(false); | ||
| // Task is waiting for TaskGroup slot | ||
| when(taskGroupCoordinator.isTaskWaitingForTaskGroupSlot(taskInstance)).thenReturn(true); | ||
|
|
||
| taskSubmittedStateAction.onKillEvent(workflowExecution, taskExecution, null); | ||
|
|
||
| verify(taskGroupCoordinator).releaseTaskGroupSlot(taskInstance); | ||
| verify(workflowEventBus).publish(any(TaskKilledLifecycleEvent.class)); | ||
| // Should NOT publish a delayed TaskKillLifecycleEvent | ||
| verify(workflowEventBus, never()).publish(any(TaskKillLifecycleEvent.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void onKillEvent_taskInDispatchQueue_shouldKillDirectly() { | ||
| // Task is in dispatch queue | ||
| when(workerGroupDispatcherCoordinator.removeTask(taskExecution)).thenReturn(true); | ||
|
|
||
| taskSubmittedStateAction.onKillEvent(workflowExecution, taskExecution, null); | ||
|
|
||
| verify(workflowEventBus).publish(any(TaskKilledLifecycleEvent.class)); | ||
| // Should NOT check TaskGroup since task was removed from dispatch queue | ||
| verify(taskGroupCoordinator, never()).isTaskWaitingForTaskGroupSlot(any()); | ||
| } | ||
|
|
||
| @Test | ||
| void onKillEvent_taskNotInDispatchQueueAndNotWaiting_shouldRetryAfter5s() { | ||
| // Task not in dispatch queue | ||
| when(workerGroupDispatcherCoordinator.removeTask(taskExecution)).thenReturn(false); | ||
| // Task is NOT waiting for TaskGroup slot | ||
| when(taskGroupCoordinator.isTaskWaitingForTaskGroupSlot(taskInstance)).thenReturn(false); | ||
|
|
||
| taskSubmittedStateAction.onKillEvent(workflowExecution, taskExecution, null); | ||
|
|
||
| verify(taskGroupCoordinator, never()).releaseTaskGroupSlot(any()); | ||
| // Should publish a delayed TaskKillLifecycleEvent (retry after 5s) | ||
| verify(workflowEventBus).publish(any(TaskKillLifecycleEvent.class)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may result in a state error due to concurrency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, there is a concurrency issue with the TaskGroupCoordinator's periodic task. However, the leaked slot will be fixed by amendTaskGroupUseSize eventually, and after the task enters PAUSE state, the dispatch event triggered by TGC's RPC will be safely ignored (just a warn log). So in practice there's no real impact. Is this acceptable? I haven't come up with a clean way to fully fix the concurrency yet.