Skip to content

Commit

Permalink
"erigon snapsots retire": to build all files (#9979)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Apr 18, 2024
1 parent cac82df commit 014aeff
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
2 changes: 0 additions & 2 deletions erigon-lib/state/aggregator_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ func (a *AggregatorV3) OpenFolder(readonly bool) error {
}

func (a *AggregatorV3) OpenList(files []string, readonly bool) error {
//log.Warn("[dbg] OpenList", "l", files)

a.filesMutationLock.Lock()
defer a.filesMutationLock.Unlock()
eg := &errgroup.Group{}
Expand Down
1 change: 1 addition & 0 deletions eth/stagedsync/stage_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func SnapshotsPrune(s *PruneState, initialCycle bool, cfg SnapshotsCfg, ctx cont
} else {
cfg.blockRetire.SetWorkers(1)
}

cfg.blockRetire.RetireBlocksInBackground(ctx, minBlockNumber, s.ForwardProgress, log.LvlDebug, func(downloadRequest []services.DownloadRequest) error {
if cfg.snapshotDownloader != nil && !reflect.ValueOf(cfg.snapshotDownloader).IsNil() {
if err := snapshotsync.RequestSnapshotsDownload(ctx, downloadRequest, cfg.snapshotDownloader); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions turbo/snapshotsync/freezeblocks/block_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,6 @@ func (r *BlockReader) txnByID(txnID uint64, sn *Segment, buf []byte) (txn types.
}

func (r *BlockReader) txnByHash(txnHash common.Hash, segments []*Segment, buf []byte) (types.Transaction, uint64, bool, error) {
fmt.Printf("[dbg] txnByHash1\n")
for i := len(segments) - 1; i >= 0; i-- {
sn := segments[i]

Expand Down Expand Up @@ -900,7 +899,6 @@ func (r *BlockReader) TxnLookup(_ context.Context, tx kv.Getter, txnHash common.
return 0, false, err
}

fmt.Printf("[dbg] txnByHash0: %t\n", n != nil)
if n != nil {
return *n, true, nil
}
Expand Down
61 changes: 33 additions & 28 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,47 +1361,52 @@ func (br *BlockRetire) RetireBlocksInBackground(ctx context.Context, minBlockNum
defer br.snBuildAllowed.Release(1)
}

for {
maxBlockNum := br.maxScheduledBlock.Load()
err := br.RetireBlocks(ctx, minBlockNum, maxBlockNum, lvl, seedNewSnapshots, onDeleteSnapshots)
if err != nil {
br.logger.Warn("[snapshots] retire blocks", "err", err)
return
}
}()
}

func (br *BlockRetire) RetireBlocks(ctx context.Context, minBlockNum uint64, maxBlockNum uint64, lvl log.Lvl, seedNewSnapshots func(downloadRequest []services.DownloadRequest) error, onDeleteSnapshots func(l []string) error) error {
if maxBlockNum > br.maxScheduledBlock.Load() {
br.maxScheduledBlock.Store(maxBlockNum)
}
includeBor := br.chainConfig.Bor != nil

err := br.RetireBlocks(ctx, minBlockNum, maxBlockNum, lvl, seedNewSnapshots, onDeleteSnapshots)
var err error
for {
var ok, okBor bool

if err != nil {
br.logger.Warn("[snapshots] retire blocks", "err", err)
return
}
minBlockNum = cmp.Max(br.blockReader.FrozenBlocks(), minBlockNum)
maxBlockNum = br.maxScheduledBlock.Load()

if maxBlockNum == br.maxScheduledBlock.Load() {
return
if includeBor {
// "bor snaps" can be behind "block snaps", it's ok: for example because of `kill -9` in the middle of merge
okBor, err = br.retireBorBlocks(ctx, br.blockReader.FrozenBorBlocks(), minBlockNum, lvl, seedNewSnapshots, onDeleteSnapshots)
if err != nil {
return err
}
}
}()
}

func (br *BlockRetire) RetireBlocks(ctx context.Context, minBlockNum uint64, maxBlockNum uint64, lvl log.Lvl, seedNewSnapshots func(downloadRequest []services.DownloadRequest) error, onDeleteSnapshots func(l []string) error) (err error) {
includeBor := br.chainConfig.Bor != nil
minBlockNum = cmp.Max(br.blockReader.FrozenBlocks(), minBlockNum)
if includeBor {
// "bor snaps" can be behind "block snaps", it's ok: for example because of `kill -9` in the middle of merge
_, err := br.retireBorBlocks(ctx, br.blockReader.FrozenBorBlocks(), minBlockNum, lvl, seedNewSnapshots, onDeleteSnapshots)
ok, err = br.retireBlocks(ctx, minBlockNum, maxBlockNum, lvl, seedNewSnapshots, onDeleteSnapshots)
if err != nil {
return err
}
}

_, err = br.retireBlocks(ctx, minBlockNum, maxBlockNum, lvl, seedNewSnapshots, onDeleteSnapshots)
if err != nil {
return err
}
if includeBor {
minBorBlockNum := cmp.Max(br.blockReader.FrozenBorBlocks(), minBlockNum)
okBor, err = br.retireBorBlocks(ctx, minBorBlockNum, maxBlockNum, lvl, seedNewSnapshots, onDeleteSnapshots)
if err != nil {
return err
}
}

if includeBor {
minBorBlockNum := cmp.Max(br.blockReader.FrozenBorBlocks(), minBlockNum)
_, err = br.retireBorBlocks(ctx, minBorBlockNum, maxBlockNum, lvl, seedNewSnapshots, onDeleteSnapshots)
if err != nil {
return err
if !(ok || okBor) {
break
}
}

return nil
}

Expand Down

0 comments on commit 014aeff

Please sign in to comment.