Skip to content

Commit

Permalink
etl: faster .Close() (#12842)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jan 24, 2025
1 parent 6c2b596 commit 7f41a5f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions erigon-lib/etl/dataprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type dataProvider interface {
Next(keyBuf, valBuf []byte) ([]byte, []byte, error)
Dispose() // Safe for repeated call, doesn't return error - means defer-friendly
Wait() error // join point for async providers
String() string
}

type fileDataProvider struct {
Expand Down Expand Up @@ -126,9 +127,14 @@ func (p *fileDataProvider) Wait() error { return p.wg.Wait() }
func (p *fileDataProvider) Dispose() {
if p.file != nil { //invariant: safe to call multiple time
p.Wait()
_ = p.file.Close()
go func(fPath string) { _ = os.Remove(fPath) }(p.file.Name())
file := p.file
p.file = nil

go func() {
filePath := file.Name()
file.Close()
_ = os.Remove(filePath)
}()
}
}

Expand Down

0 comments on commit 7f41a5f

Please sign in to comment.