@@ -77,7 +77,6 @@ func (c *Lister) workstealListing(ctx context.Context) ([]*storage.ObjectAttrs,
77
77
if err != nil {
78
78
return nil , fmt .Errorf ("creating new range splitter: %w" , err )
79
79
}
80
-
81
80
g , ctx := errgroup .WithContext (ctx )
82
81
// Initialize all workers as idle.
83
82
for i := 0 ; i < c .parallelism ; i ++ {
@@ -126,17 +125,12 @@ func (w *worker) doWorkstealListing(ctx context.Context) error {
126
125
// If a worker is idle, sleep for a while before checking the next update.
127
126
// Worker status is changed to active when it finds work in range channel.
128
127
if w .status == idle {
129
- if len (w .lister .ranges ) == 0 {
130
- time .Sleep (sleepDurationWhenIdle )
128
+ select {
129
+ case newRange := <- w .lister .ranges :
130
+ <- w .idleChannel
131
+ w .updateWorker (newRange .startRange , newRange .endRange , active )
132
+ case <- time .After (sleepDurationWhenIdle ):
131
133
continue
132
- } else {
133
- select {
134
- case newRange := <- w .lister .ranges :
135
- <- w .idleChannel
136
- w .updateWorker (newRange .startRange , newRange .endRange , active )
137
- case <- time .After (sleepDurationWhenIdle ):
138
- continue
139
- }
140
134
}
141
135
}
142
136
// Active worker to list next page of objects within the range
@@ -157,7 +151,7 @@ func (w *worker) doWorkstealListing(ctx context.Context) error {
157
151
158
152
// If listing not complete and idle workers are available, split the range
159
153
// and give half of work to idle worker.
160
- for len (w .idleChannel )- len (w .lister .ranges ) > 0 && ctx .Err () == nil {
154
+ if len (w .idleChannel )- len (w .lister .ranges ) > 0 && ctx .Err () == nil {
161
155
// Split range and upload half of work for idle worker.
162
156
splitPoint , err := w .rangesplitter .splitRange (w .startRange , w .endRange , 1 )
163
157
if err != nil {
0 commit comments