Prevent double retiring of the same interval, prevent hiding errors (#4325)

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
ledgerwatch 2022-06-02 02:49:24 +01:00 committed by GitHub
parent e0ac654da5
commit b06b4b4c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -898,10 +898,15 @@ func CanDeleteTo(curBlockNum uint64, snapshots *RoSnapshots) (blockTo uint64) {
return cmp.Min(hardLimit, snapshots.BlocksAvailable()+1)
}
func (br *BlockRetire) RetireBlocksInBackground(ctx context.Context, blockFrom, blockTo uint64, chainID uint256.Int, lvl log.Lvl) {
br.result = nil
if br.working.Load() {
// go-routine is still working
return
}
if br.result != nil {
// Prevent invocation for the same range twice, result needs to be cleared in the Result() function
return
}
br.result = nil
br.wg.Add(1)
go func() {
@ -928,7 +933,7 @@ func retireBlocks(ctx context.Context, blockFrom, blockTo uint64, chainID uint25
if err := DumpBlocks(ctx, blockFrom, blockTo, snap.DEFAULT_SEGMENT_SIZE, tmpDir, snapshots.Dir(), db, workers, lvl); err != nil {
return fmt.Errorf("DumpBlocks: %w", err)
}
if err := snapshots.Reopen(); err != nil {
if err := snapshots.ReopenSegments(); err != nil {
return fmt.Errorf("ReopenSegments: %w", err)
}
idxWorkers := workers
@ -947,6 +952,9 @@ func retireBlocks(ctx context.Context, blockFrom, blockTo uint64, chainID uint25
if err != nil {
return err
}
if err := snapshots.Reopen(); err != nil {
return fmt.Errorf("Reopen: %w", err)
}
// start seed large .seg of large size
req := &proto_downloader.DownloadRequest{Items: make([]*proto_downloader.DownloadItem, 0, len(snap.AllSnapshotTypes))}
for _, r := range ranges {