Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migration): improve job progress logging in MigrateStateTree #329

Merged
merged 7 commits into from
Dec 3, 2024
15 changes: 10 additions & 5 deletions migration/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migration

import (
"context"
"fmt"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -106,13 +107,17 @@ func RunMigration(ctx context.Context, cfg Config, cache MigrationCache, store c
for {
select {
case <-time.After(cfg.ProgressLogPeriod):
jobsNow := jobCount // Snapshot values to avoid incorrect-looking arithmetic if they change.
doneNow := doneCount
pendingNow := jobsNow - doneNow
jobsNow := atomic.LoadUint32(&jobCount)
doneNow := atomic.LoadUint32(&doneCount)
elapsed := time.Since(startTime)
rate := float64(doneNow) / elapsed.Seconds()
log.Log(rt.INFO, "%d jobs created, %d done, %d pending after %v (%.0f/s)",
jobsNow, doneNow, pendingNow, elapsed, rate)

jobsStr := fmt.Sprintf("%d", jobsNow)
doneStr := fmt.Sprintf("%d", doneNow)
rateStr := fmt.Sprintf("%.0f", rate)

log.Log(rt.INFO, "Performing migration: %s of %s jobs processed (%s/s) [%v elapsed]",
doneStr, jobsStr, rateStr, elapsed.Round(time.Second))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is looking good @virajbhartiya but why do we have the separate fmt.Sprintf's for the numbers and not just using the log.Log for that? If we're not pulling apart the Log call manually in lotus then they can be arbitrary values so numbers should be fine, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right that could be done directly, thanks!, updated it

case <-workersFinished:
return
case <-ctx.Done():
Expand Down
Loading