| 78 | } |
| 79 | |
| 80 | func (c *Coordinator) prepare(ctx context.Context, workers []Worker, wb WriteBatch) (err error) { |
| 81 | errs := make([]error, len(workers)) |
| 82 | wg := sync.WaitGroup{} |
| 83 | workerFunc := func(n Worker, e *error, wg *sync.WaitGroup) { |
| 84 | defer wg.Done() |
| 85 | |
| 86 | *e = n.Prepare(ctx, wb) |
| 87 | } |
| 88 | |
| 89 | for index, worker := range workers { |
| 90 | wg.Add(1) |
| 91 | go workerFunc(worker, &errs[index], &wg) |
| 92 | } |
| 93 | |
| 94 | wg.Wait() |
| 95 | |
| 96 | var index int |
| 97 | for index, err = range errs { |
| 98 | if err != nil { |
| 99 | log.WithField("worker", workers[index]).WithError(err).Debug("prepare failed") |
| 100 | return |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | func (c *Coordinator) rollback(ctx context.Context, workers []Worker, wb WriteBatch) (err error) { |
| 108 | errs := make([]error, len(workers)) |