diff --git a/manager/scheduler/constraint_test.go b/manager/scheduler/constraint_test.go index 6fd6945b54..7bd378139e 100644 --- a/manager/scheduler/constraint_test.go +++ b/manager/scheduler/constraint_test.go @@ -55,7 +55,7 @@ func setupEnv() { }, }, Tasks: make(map[string]*api.Task), - DesiredRunningTasksCountByService: make(map[string]int), + ActiveTasksCountByService: make(map[string]int), } } diff --git a/manager/scheduler/nodeinfo.go b/manager/scheduler/nodeinfo.go index a3013b284f..8b1ede9f84 100644 --- a/manager/scheduler/nodeinfo.go +++ b/manager/scheduler/nodeinfo.go @@ -11,10 +11,10 @@ import ( // NodeInfo contains a node and some additional metadata. type NodeInfo struct { *api.Node - Tasks map[string]*api.Task - DesiredRunningTasksCount int - DesiredRunningTasksCountByService map[string]int - AvailableResources api.Resources + Tasks map[string]*api.Task + ActiveTasksCount int + ActiveTasksCountByService map[string]int + AvailableResources api.Resources // recentFailures is a map from service ID to the timestamps of the // most recent failures the node has experienced from replicas of that @@ -28,9 +28,9 @@ func newNodeInfo(n *api.Node, tasks map[string]*api.Task, availableResources api nodeInfo := NodeInfo{ Node: n, Tasks: make(map[string]*api.Task), - DesiredRunningTasksCountByService: make(map[string]int), - AvailableResources: availableResources, - recentFailures: make(map[string][]time.Time), + ActiveTasksCountByService: make(map[string]int), + AvailableResources: availableResources, + recentFailures: make(map[string][]time.Time), } for _, t := range tasks { @@ -48,9 +48,9 @@ func (nodeInfo *NodeInfo) removeTask(t *api.Task) bool { } delete(nodeInfo.Tasks, t.ID) - if oldTask.DesiredState == api.TaskStateRunning { - nodeInfo.DesiredRunningTasksCount-- - nodeInfo.DesiredRunningTasksCountByService[t.ServiceID]-- + if oldTask.DesiredState <= api.TaskStateRunning { + nodeInfo.ActiveTasksCount-- + nodeInfo.ActiveTasksCountByService[t.ServiceID]-- } reservations := taskReservations(t.Spec) @@ -65,15 +65,15 @@ func (nodeInfo *NodeInfo) removeTask(t *api.Task) bool { func (nodeInfo *NodeInfo) addTask(t *api.Task) bool { oldTask, ok := nodeInfo.Tasks[t.ID] if ok { - if t.DesiredState == api.TaskStateRunning && oldTask.DesiredState != api.TaskStateRunning { + if t.DesiredState <= api.TaskStateRunning && oldTask.DesiredState > api.TaskStateRunning { nodeInfo.Tasks[t.ID] = t - nodeInfo.DesiredRunningTasksCount++ - nodeInfo.DesiredRunningTasksCountByService[t.ServiceID]++ + nodeInfo.ActiveTasksCount++ + nodeInfo.ActiveTasksCountByService[t.ServiceID]++ return true - } else if t.DesiredState != api.TaskStateRunning && oldTask.DesiredState == api.TaskStateRunning { + } else if t.DesiredState > api.TaskStateRunning && oldTask.DesiredState <= api.TaskStateRunning { nodeInfo.Tasks[t.ID] = t - nodeInfo.DesiredRunningTasksCount-- - nodeInfo.DesiredRunningTasksCountByService[t.ServiceID]-- + nodeInfo.ActiveTasksCount-- + nodeInfo.ActiveTasksCountByService[t.ServiceID]-- return true } return false @@ -84,9 +84,9 @@ func (nodeInfo *NodeInfo) addTask(t *api.Task) bool { nodeInfo.AvailableResources.MemoryBytes -= reservations.MemoryBytes nodeInfo.AvailableResources.NanoCPUs -= reservations.NanoCPUs - if t.DesiredState == api.TaskStateRunning { - nodeInfo.DesiredRunningTasksCount++ - nodeInfo.DesiredRunningTasksCountByService[t.ServiceID]++ + if t.DesiredState <= api.TaskStateRunning { + nodeInfo.ActiveTasksCount++ + nodeInfo.ActiveTasksCountByService[t.ServiceID]++ } return true diff --git a/manager/scheduler/nodeset.go b/manager/scheduler/nodeset.go index 2f8ae51ca1..6e0b18e49d 100644 --- a/manager/scheduler/nodeset.go +++ b/manager/scheduler/nodeset.go @@ -35,8 +35,8 @@ func (ns *nodeSet) addOrUpdateNode(n NodeInfo) { if n.Tasks == nil { n.Tasks = make(map[string]*api.Task) } - if n.DesiredRunningTasksCountByService == nil { - n.DesiredRunningTasksCountByService = make(map[string]int) + if n.ActiveTasksCountByService == nil { + n.ActiveTasksCountByService = make(map[string]int) } if n.recentFailures == nil { n.recentFailures = make(map[string][]time.Time) @@ -96,8 +96,8 @@ func (ns *nodeSet) tree(serviceID string, preferences []*api.PlacementPreference // sure that the tree structure is not affected by // which properties nodes have and don't have. - if node.DesiredRunningTasksCountByService != nil { - tree.tasks += node.DesiredRunningTasksCountByService[serviceID] + if node.ActiveTasksCountByService != nil { + tree.tasks += node.ActiveTasksCountByService[serviceID] } if tree.next == nil { diff --git a/manager/scheduler/scheduler.go b/manager/scheduler/scheduler.go index c790ee8f47..55420a2d42 100644 --- a/manager/scheduler/scheduler.go +++ b/manager/scheduler/scheduler.go @@ -517,8 +517,8 @@ func (s *Scheduler) scheduleTaskGroup(ctx context.Context, taskGroup map[string] } } - tasksByServiceA := a.DesiredRunningTasksCountByService[t.ServiceID] - tasksByServiceB := b.DesiredRunningTasksCountByService[t.ServiceID] + tasksByServiceA := a.ActiveTasksCountByService[t.ServiceID] + tasksByServiceB := b.ActiveTasksCountByService[t.ServiceID] if tasksByServiceA < tasksByServiceB { return true @@ -528,7 +528,7 @@ func (s *Scheduler) scheduleTaskGroup(ctx context.Context, taskGroup map[string] } // Total number of tasks breaks ties. - return a.DesiredRunningTasksCount < b.DesiredRunningTasksCount + return a.ActiveTasksCount < b.ActiveTasksCount } var prefs []*api.PlacementPreference