e3: buildFiles: return error when can (#763)

This commit is contained in:
Alex Sharov 2022-12-04 16:19:49 +07:00 committed by GitHub
parent 5a1726b107
commit 81be3e5d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -279,7 +279,7 @@ func (a *Aggregator22) buildFiles(ctx context.Context, step uint64, txFrom, txTo
}() }()
//var wg sync.WaitGroup //var wg sync.WaitGroup
//wg.Add(7) //wg.Add(7)
errCh := make(chan error, 7) //errCh := make(chan error, 7)
//go func() { //go func() {
// defer wg.Done() // defer wg.Done()
var err error var err error
@ -287,11 +287,13 @@ func (a *Aggregator22) buildFiles(ctx context.Context, step uint64, txFrom, txTo
ac.accounts, err = a.accounts.collate(step, txFrom, txTo, tx, logEvery) ac.accounts, err = a.accounts.collate(step, txFrom, txTo, tx, logEvery)
return err return err
}); err != nil { }); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
if sf.accounts, err = a.accounts.buildFiles(ctx, step, ac.accounts); err != nil { if sf.accounts, err = a.accounts.buildFiles(ctx, step, ac.accounts); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
//}() //}()
// //
@ -302,11 +304,13 @@ func (a *Aggregator22) buildFiles(ctx context.Context, step uint64, txFrom, txTo
ac.storage, err = a.storage.collate(step, txFrom, txTo, tx, logEvery) ac.storage, err = a.storage.collate(step, txFrom, txTo, tx, logEvery)
return err return err
}); err != nil { }); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
if sf.storage, err = a.storage.buildFiles(ctx, step, ac.storage); err != nil { if sf.storage, err = a.storage.buildFiles(ctx, step, ac.storage); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
//}() //}()
//go func() { //go func() {
@ -316,11 +320,13 @@ func (a *Aggregator22) buildFiles(ctx context.Context, step uint64, txFrom, txTo
ac.code, err = a.code.collate(step, txFrom, txTo, tx, logEvery) ac.code, err = a.code.collate(step, txFrom, txTo, tx, logEvery)
return err return err
}); err != nil { }); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
if sf.code, err = a.code.buildFiles(ctx, step, ac.code); err != nil { if sf.code, err = a.code.buildFiles(ctx, step, ac.code); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
//}() //}()
//go func() { //go func() {
@ -330,11 +336,13 @@ func (a *Aggregator22) buildFiles(ctx context.Context, step uint64, txFrom, txTo
ac.logAddrs, err = a.logAddrs.collate(ctx, txFrom, txTo, tx, logEvery) ac.logAddrs, err = a.logAddrs.collate(ctx, txFrom, txTo, tx, logEvery)
return err return err
}); err != nil { }); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
if sf.logAddrs, err = a.logAddrs.buildFiles(ctx, step, ac.logAddrs); err != nil { if sf.logAddrs, err = a.logAddrs.buildFiles(ctx, step, ac.logAddrs); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
//}() //}()
//go func() { //go func() {
@ -344,11 +352,13 @@ func (a *Aggregator22) buildFiles(ctx context.Context, step uint64, txFrom, txTo
ac.logTopics, err = a.logTopics.collate(ctx, txFrom, txTo, tx, logEvery) ac.logTopics, err = a.logTopics.collate(ctx, txFrom, txTo, tx, logEvery)
return err return err
}); err != nil { }); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
if sf.logTopics, err = a.logTopics.buildFiles(ctx, step, ac.logTopics); err != nil { if sf.logTopics, err = a.logTopics.buildFiles(ctx, step, ac.logTopics); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
//}() //}()
//go func() { //go func() {
@ -358,11 +368,13 @@ func (a *Aggregator22) buildFiles(ctx context.Context, step uint64, txFrom, txTo
ac.tracesFrom, err = a.tracesFrom.collate(ctx, txFrom, txTo, tx, logEvery) ac.tracesFrom, err = a.tracesFrom.collate(ctx, txFrom, txTo, tx, logEvery)
return err return err
}); err != nil { }); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
if sf.tracesFrom, err = a.tracesFrom.buildFiles(ctx, step, ac.tracesFrom); err != nil { if sf.tracesFrom, err = a.tracesFrom.buildFiles(ctx, step, ac.tracesFrom); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
//}() //}()
//go func() { //go func() {
@ -372,27 +384,29 @@ func (a *Aggregator22) buildFiles(ctx context.Context, step uint64, txFrom, txTo
ac.tracesTo, err = a.tracesTo.collate(ctx, txFrom, txTo, tx, logEvery) ac.tracesTo, err = a.tracesTo.collate(ctx, txFrom, txTo, tx, logEvery)
return err return err
}); err != nil { }); err != nil {
errCh <- err return sf, err
//errCh <- err
} }
if sf.tracesTo, err = a.tracesTo.buildFiles(ctx, step, ac.tracesTo); err != nil { if sf.tracesTo, err = a.tracesTo.buildFiles(ctx, step, ac.tracesTo); err != nil {
errCh <- err return sf, err
// errCh <- err
} }
//}() //}()
//go func() { //go func() {
// wg.Wait() // wg.Wait()
close(errCh) //close(errCh)
//}() //}()
var lastError error //var lastError error
for err := range errCh { //for err := range errCh {
if err != nil { // if err != nil {
lastError = err // lastError = err
} // }
} //}
if lastError == nil { //if lastError == nil {
closeColl = false closeColl = false
} //}
return sf, lastError return sf, nil
} }
type Agg22StaticFiles struct { type Agg22StaticFiles struct {