@@ -14,12 +14,15 @@ type SchedulerTaskManager struct {
1414 allTaskMap map [int32 ]* structure.TaskInfo
1515 allTaskQueue []* structure.TaskInfo
1616 startTaskQueue []* structure.TaskInfo
17+ // onGoingTasks
18+ notCompleteTasks map [int32 ]* structure.TaskInfo
1719 // A map from task ID to worker group can be used to track which worker group is handling which task.
1820 taskToworkerGroupMap map [int32 ]string
1921}
2022
2123func (t * SchedulerTaskManager ) Init () * SchedulerTaskManager {
2224 t .allTaskMap = make (map [int32 ]* structure.TaskInfo )
25+ t .notCompleteTasks = make (map [int32 ]* structure.TaskInfo )
2326 t .taskToworkerGroupMap = make (map [int32 ]string )
2427 return t
2528}
@@ -38,10 +41,23 @@ func (t *SchedulerTaskManager) QueueTask(taskInfo *structure.TaskInfo) (bool, er
3841 // Add the task to the task map
3942 t .allTaskMap [taskInfo .ID ] = taskInfo
4043 t .allTaskQueue = append (t .allTaskQueue , taskInfo )
44+ t .notCompleteTasks [taskInfo .ID ] = taskInfo
4145 t .AssignGroup (taskInfo )
4246 return true , nil
4347}
4448
49+ func (t * SchedulerTaskManager ) RefreshTaskToWorkerGroupMap () {
50+ defer t .Unlock (t .Lock ())
51+
52+ for _ , taskInfo := range t .GetAllTasksNotComplete () {
53+ if taskInfo == nil {
54+ continue
55+ }
56+ t .AssignGroup (taskInfo )
57+ t .taskToworkerGroupMap [taskInfo .ID ] = workerMgr .ApplyGroup (taskInfo .SpaceName , taskInfo .GraphName )
58+ }
59+ }
60+
4561// Only for debug or test, get task start sequence
4662func (t * SchedulerTaskManager ) AddTaskStartSequence (taskID int32 ) error {
4763 if _ , exists := t .allTaskMap [taskID ]; ! exists {
@@ -64,6 +80,15 @@ func (t *SchedulerTaskManager) RemoveTask(taskID int32) error {
6480 }
6581 }
6682 delete (t .taskToworkerGroupMap , taskID )
83+ delete (t .notCompleteTasks , taskID )
84+ return nil
85+ }
86+
87+ func (t * SchedulerTaskManager ) MarkTaskComplete (taskID int32 ) error {
88+ if _ , exists := t .allTaskMap [taskID ]; ! exists {
89+ return errors .New ("task not found" )
90+ }
91+ delete (t .notCompleteTasks , taskID )
6792 return nil
6893}
6994
@@ -106,9 +131,17 @@ func (t *SchedulerTaskManager) GetAllTasks() []*structure.TaskInfo {
106131 return tasks
107132}
108133
134+ func (t * SchedulerTaskManager ) GetAllTasksNotComplete () []* structure.TaskInfo {
135+ tasks := make ([]* structure.TaskInfo , 0 , len (t .allTaskMap ))
136+ for _ , task := range t .notCompleteTasks {
137+ tasks = append (tasks , task )
138+ }
139+ return tasks
140+ }
141+
109142func (t * SchedulerTaskManager ) GetAllTasksWaitng () []* structure.TaskInfo {
110143 tasks := make ([]* structure.TaskInfo , 0 , len (t .allTaskMap ))
111- for _ , task := range t .allTaskMap {
144+ for _ , task := range t .GetAllTasksNotComplete () {
112145 if task .State == structure .TaskStateWaiting {
113146 tasks = append (tasks , task )
114147 }
@@ -118,7 +151,7 @@ func (t *SchedulerTaskManager) GetAllTasksWaitng() []*structure.TaskInfo {
118151
119152func (t * SchedulerTaskManager ) GetTasksInQueue (space string ) []* structure.TaskInfo {
120153 tasks := make ([]* structure.TaskInfo , 0 )
121- for _ , task := range t .allTaskQueue {
154+ for _ , task := range t .GetAllTasksNotComplete () {
122155 if task .SpaceName == space {
123156 tasks = append (tasks , task )
124157 }
@@ -153,9 +186,12 @@ func (t *SchedulerTaskManager) GetTaskStartSequence(queryTasks []int32) []*struc
153186
154187func (t * SchedulerTaskManager ) GetTaskToWorkerGroupMap () map [int32 ]string {
155188 // Return a copy of the worker group map to avoid external modifications
156- groupMap := make (map [int32 ]string , len (t .taskToworkerGroupMap ))
157- for k , v := range t .taskToworkerGroupMap {
158- groupMap [k ] = v
189+ taskNotComplete := t .GetAllTasksNotComplete ()
190+ groupMap := make (map [int32 ]string , len (taskNotComplete ))
191+ for _ , task := range taskNotComplete {
192+ if group , exists := t .taskToworkerGroupMap [task .ID ]; exists {
193+ groupMap [task .ID ] = group
194+ }
159195 }
160196 return groupMap
161197}
0 commit comments