Skip to content

Commit

Permalink
Better progress logging for initSnapshotLock (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtdcode authored Jun 13, 2024
1 parent 708ef54 commit cc88640
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func initSnapshotLock(ctx context.Context, cfg *downloadercfg.Cfg, db kv.RoDB, s

g, ctx := errgroup.WithContext(ctx)
g.SetLimit(runtime.GOMAXPROCS(-1) * 4)
var i atomic.Int32
var done atomic.Int32

logEvery := time.NewTicker(20 * time.Second)
defer logEvery.Stop()
Expand All @@ -553,8 +553,7 @@ func initSnapshotLock(ctx context.Context, cfg *downloadercfg.Cfg, db kv.RoDB, s
file := file

g.Go(func() error {
i.Add(1)

defer done.Add(1)
fileInfo, isStateFile, ok := snaptype.ParseFileName(snapDir, file)

if !ok {
Expand Down Expand Up @@ -663,15 +662,15 @@ func initSnapshotLock(ctx context.Context, cfg *downloadercfg.Cfg, db kv.RoDB, s
}

func() {
for int(i.Load()) < len(files) {
for int(done.Load()) < len(files) {
select {
case <-ctx.Done():
return // g.Wait() will return right error
case <-logEvery.C:
if int(i.Load()) == len(files) {
if int(done.Load()) == len(files) {
return
}
log.Info("[snapshots] Initiating snapshot-lock", "progress", fmt.Sprintf("%d/%d", i.Load(), len(files)))
log.Info("[snapshots] Initiating snapshot-lock", "progress", fmt.Sprintf("%d/%d", done.Load(), len(files)))
}
}
}()
Expand Down

0 comments on commit cc88640

Please sign in to comment.