File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -70,14 +70,27 @@ func (p *IncrementalWorkerPicker) cleanup() {
70
70
p .workers = activeWorkers
71
71
}
72
72
73
+ func (p * IncrementalWorkerPicker ) findAvailable () int {
74
+ for idx , w := range p .workers {
75
+ if ! w .IsFull () {
76
+ return idx
77
+ }
78
+ }
79
+
80
+ return - 1
81
+ }
82
+
73
83
func (p * IncrementalWorkerPicker ) pickInternal () (* ClientWorker , error , bool ) {
74
84
p .access .Lock ()
75
85
defer p .access .Unlock ()
76
86
77
- for _ , w := range p .workers {
78
- if ! w .IsFull () {
79
- return w , nil , false
87
+ idx := p .findAvailable ()
88
+ if idx >= 0 {
89
+ n := len (p .workers )
90
+ if n > 1 && idx != n - 1 {
91
+ p .workers [n - 1 ], p .workers [idx ] = p .workers [idx ], p .workers [n - 1 ]
80
92
}
93
+ return p .workers [idx ], nil , false
81
94
}
82
95
83
96
p .cleanup ()
You can’t perform that action at this time.
0 commit comments