Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
| ... | ... |
@@ -101,7 +101,7 @@ github.com/docker/containerd 595e75c212d19a81d2b808a518fe1afc1391dad5 |
| 101 | 101 |
github.com/tonistiigi/fifo 1405643975692217d6720f8b54aeee1bf2cd5cf4 |
| 102 | 102 |
|
| 103 | 103 |
# cluster |
| 104 |
-github.com/docker/swarmkit f93948cb430facd540e3c65c606384a89b3ac40f |
|
| 104 |
+github.com/docker/swarmkit 17756457ad6dc4d8a639a1f0b7a85d1b65a617bb |
|
| 105 | 105 |
github.com/golang/mock bd3c8e81be01eef76d4b503f5e687d2d1354d2d9 |
| 106 | 106 |
github.com/gogo/protobuf v0.3 |
| 107 | 107 |
github.com/cloudflare/cfssl 7fb22c8cba7ecaf98e4082d22d65800cf45e042a |
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package scheduler |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "container/list" |
|
| 5 | 4 |
"time" |
| 6 | 5 |
|
| 7 | 6 |
"github.com/docker/swarmkit/api" |
| ... | ... |
@@ -30,7 +29,7 @@ type schedulingDecision struct {
|
| 30 | 30 |
// Scheduler assigns tasks to nodes. |
| 31 | 31 |
type Scheduler struct {
|
| 32 | 32 |
store *store.MemoryStore |
| 33 |
- unassignedTasks *list.List |
|
| 33 |
+ unassignedTasks map[string]*api.Task |
|
| 34 | 34 |
// preassignedTasks already have NodeID, need resource validation |
| 35 | 35 |
preassignedTasks map[string]*api.Task |
| 36 | 36 |
nodeSet nodeSet |
| ... | ... |
@@ -47,7 +46,7 @@ type Scheduler struct {
|
| 47 | 47 |
func New(store *store.MemoryStore) *Scheduler {
|
| 48 | 48 |
return &Scheduler{
|
| 49 | 49 |
store: store, |
| 50 |
- unassignedTasks: list.New(), |
|
| 50 |
+ unassignedTasks: make(map[string]*api.Task), |
|
| 51 | 51 |
preassignedTasks: make(map[string]*api.Task), |
| 52 | 52 |
allTasks: make(map[string]*api.Task), |
| 53 | 53 |
stopChan: make(chan struct{}),
|
| ... | ... |
@@ -191,7 +190,7 @@ func (s *Scheduler) Stop() {
|
| 191 | 191 |
|
| 192 | 192 |
// enqueue queues a task for scheduling. |
| 193 | 193 |
func (s *Scheduler) enqueue(t *api.Task) {
|
| 194 |
- s.unassignedTasks.PushBack(t) |
|
| 194 |
+ s.unassignedTasks[t.ID] = t |
|
| 195 | 195 |
} |
| 196 | 196 |
|
| 197 | 197 |
func (s *Scheduler) createTask(ctx context.Context, t *api.Task) int {
|
| ... | ... |
@@ -333,15 +332,12 @@ func (s *Scheduler) processPreassignedTasks(ctx context.Context) {
|
| 333 | 333 |
// tick attempts to schedule the queue. |
| 334 | 334 |
func (s *Scheduler) tick(ctx context.Context) {
|
| 335 | 335 |
tasksByCommonSpec := make(map[string]map[string]*api.Task) |
| 336 |
- schedulingDecisions := make(map[string]schedulingDecision, s.unassignedTasks.Len()) |
|
| 336 |
+ schedulingDecisions := make(map[string]schedulingDecision, len(s.unassignedTasks)) |
|
| 337 | 337 |
|
| 338 |
- var next *list.Element |
|
| 339 |
- for e := s.unassignedTasks.Front(); e != nil; e = next {
|
|
| 340 |
- next = e.Next() |
|
| 341 |
- t := s.allTasks[e.Value.(*api.Task).ID] |
|
| 338 |
+ for taskID, t := range s.unassignedTasks {
|
|
| 342 | 339 |
if t == nil || t.NodeID != "" {
|
| 343 | 340 |
// task deleted or already assigned |
| 344 |
- s.unassignedTasks.Remove(e) |
|
| 341 |
+ delete(s.unassignedTasks, taskID) |
|
| 345 | 342 |
continue |
| 346 | 343 |
} |
| 347 | 344 |
|
| ... | ... |
@@ -362,8 +358,8 @@ func (s *Scheduler) tick(ctx context.Context) {
|
| 362 | 362 |
if tasksByCommonSpec[taskGroupKey] == nil {
|
| 363 | 363 |
tasksByCommonSpec[taskGroupKey] = make(map[string]*api.Task) |
| 364 | 364 |
} |
| 365 |
- tasksByCommonSpec[taskGroupKey][t.ID] = t |
|
| 366 |
- s.unassignedTasks.Remove(e) |
|
| 365 |
+ tasksByCommonSpec[taskGroupKey][taskID] = t |
|
| 366 |
+ delete(s.unassignedTasks, taskID) |
|
| 367 | 367 |
} |
| 368 | 368 |
|
| 369 | 369 |
for _, taskGroup := range tasksByCommonSpec {
|
| ... | ... |
@@ -540,6 +536,12 @@ func (s *Scheduler) scheduleTaskGroup(ctx context.Context, taskGroup map[string] |
| 540 | 540 |
failedConstraints := make(map[int]bool) // key is index in nodes slice |
| 541 | 541 |
nodeIter := 0 |
| 542 | 542 |
for taskID, t := range taskGroup {
|
| 543 |
+ // Skip tasks which were already scheduled because they ended |
|
| 544 |
+ // up in two groups at once. |
|
| 545 |
+ if _, exists := schedulingDecisions[taskID]; exists {
|
|
| 546 |
+ continue |
|
| 547 |
+ } |
|
| 548 |
+ |
|
| 543 | 549 |
n := &nodes[nodeIter%len(nodes)] |
| 544 | 550 |
|
| 545 | 551 |
log.G(ctx).WithField("task.id", t.ID).Debugf("assigning to node %s", n.ID)
|