Skip to content

Commit 42c9e33

Browse files
committed
Revert "cleanup"
This reverts commit e2a259a.
1 parent e2a259a commit 42c9e33

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

tasks/scheduler.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ type deliverTxTask struct {
5252
ValidateCh chan struct{}
5353
}
5454

55-
func (dt *deliverTxTask) Reset() {
55+
func (dt *deliverTxTask) Increment() {
56+
dt.Incarnation++
5657
dt.Status = statusPending
5758
dt.Response = nil
5859
dt.Abort = nil
@@ -62,10 +63,6 @@ func (dt *deliverTxTask) Reset() {
6263
dt.ValidateCh = make(chan struct{}, 1)
6364
}
6465

65-
func (dt *deliverTxTask) Increment() {
66-
dt.Incarnation++
67-
}
68-
6966
// Scheduler processes tasks concurrently
7067
type Scheduler interface {
7168
ProcessAll(ctx sdk.Context, reqs []*sdk.DeliverTxEntry) ([]types.ResponseDeliverTx, error)
@@ -247,8 +244,8 @@ func (s *scheduler) validateTask(ctx sdk.Context, task *deliverTxTask) bool {
247244
_, span := s.traceSpan(ctx, "SchedulerValidate", task)
248245
defer span.End()
249246

250-
if s.shouldRerun(task) {
251-
task.Reset()
247+
if ok := s.shouldRerun(task); ok {
248+
task.Increment()
252249
return false
253250
}
254251
return true
@@ -275,8 +272,7 @@ func (s *scheduler) validateAll(ctx sdk.Context, tasks []*deliverTxTask) ([]*del
275272
wg.Add(1)
276273
go func(task *deliverTxTask) {
277274
defer wg.Done()
278-
if !s.validateTask(ctx, task) {
279-
task.Increment()
275+
if ok := s.validateTask(ctx, task); !ok {
280276
mx.Lock()
281277
res = append(res, task)
282278
mx.Unlock()
@@ -304,10 +300,9 @@ func (s *scheduler) executeAll(ctx sdk.Context, tasks []*deliverTxTask) error {
304300
workers = len(tasks)
305301
}
306302

307-
// validationWg waits for all validations to complete
308-
// validations happen in separate goroutines in order to wait on previous index
309-
validationWg := &sync.WaitGroup{}
310-
validationWg.Add(len(tasks))
303+
wg := &sync.WaitGroup{}
304+
305+
wg.Add(len(tasks))
311306
for i := 0; i < workers; i++ {
312307
grp.Go(func() error {
313308
for {
@@ -318,21 +313,27 @@ func (s *scheduler) executeAll(ctx sdk.Context, tasks []*deliverTxTask) error {
318313
if !ok {
319314
return nil
320315
}
321-
s.prepareAndRunTask(validationWg, ctx, task)
316+
s.prepareAndRunTask(wg, ctx, task)
322317
}
323318
}
324319
})
325320
}
326-
327-
for _, task := range tasks {
328-
ch <- task
329-
}
330-
close(ch)
321+
grp.Go(func() error {
322+
defer close(ch)
323+
for _, task := range tasks {
324+
select {
325+
case <-gCtx.Done():
326+
return gCtx.Err()
327+
case ch <- task:
328+
}
329+
}
330+
return nil
331+
})
331332

332333
if err := grp.Wait(); err != nil {
333334
return err
334335
}
335-
validationWg.Wait()
336+
wg.Wait()
336337

337338
return nil
338339
}
@@ -346,7 +347,6 @@ func (s *scheduler) prepareAndRunTask(wg *sync.WaitGroup, ctx sdk.Context, task
346347
go func() {
347348
defer wg.Done()
348349
defer close(task.ValidateCh)
349-
// wait on previous task to finish validation
350350
if task.Index > 0 {
351351
<-s.allTasks[task.Index-1].ValidateCh
352352
}

0 commit comments

Comments
 (0)