Skip to content

Commit 32f613e

Browse files
fix(migration): improve job progress logging (#329)
1 parent 111b58c commit 32f613e

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

migration/runner.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,14 @@ func RunMigration(ctx context.Context, cfg Config, cache MigrationCache, store c
5858
}); err != nil {
5959
return xerrors.Errorf("error iterating actors: %w", err)
6060
}
61-
log.Log(rt.INFO, "Done creating %d migration jobs after %v", jobCount, time.Since(startTime))
61+
log.Log(rt.INFO, "Done creating %d migration jobs after %v", jobCount, time.Since(startTime).Round(100*time.Millisecond))
6262
return nil
6363
})
6464

6565
// Worker threads run jobs.
6666
var workerWg sync.WaitGroup
6767
for i := uint(0); i < cfg.MaxWorkers; i++ {
6868
workerWg.Add(1)
69-
workerId := i
7069
grp.Go(func() error {
7170
defer workerWg.Done()
7271
for job := range jobCh {
@@ -91,7 +90,6 @@ func RunMigration(ctx context.Context, cfg Config, cache MigrationCache, store c
9190

9291
atomic.AddUint32(&doneCount, 1)
9392
}
94-
log.Log(rt.INFO, "Worker %d done", workerId)
9593
return nil
9694
})
9795
}
@@ -106,13 +104,13 @@ func RunMigration(ctx context.Context, cfg Config, cache MigrationCache, store c
106104
for {
107105
select {
108106
case <-time.After(cfg.ProgressLogPeriod):
109-
jobsNow := jobCount // Snapshot values to avoid incorrect-looking arithmetic if they change.
110-
doneNow := doneCount
111-
pendingNow := jobsNow - doneNow
107+
jobsNow := atomic.LoadUint32(&jobCount)
108+
doneNow := atomic.LoadUint32(&doneCount)
112109
elapsed := time.Since(startTime)
113110
rate := float64(doneNow) / elapsed.Seconds()
114-
log.Log(rt.INFO, "%d jobs created, %d done, %d pending after %v (%.0f/s)",
115-
jobsNow, doneNow, pendingNow, elapsed, rate)
111+
112+
log.Log(rt.INFO, "Performing migration: %d of %d jobs processed (%.0f/s) [%v elapsed]",
113+
doneNow, jobsNow, rate, elapsed.Round(time.Second))
116114
case <-workersFinished:
117115
return
118116
case <-ctx.Done():
@@ -127,7 +125,7 @@ func RunMigration(ctx context.Context, cfg Config, cache MigrationCache, store c
127125
workerWg.Wait()
128126
close(jobResultCh)
129127
close(workersFinished)
130-
log.Log(rt.INFO, "All workers done after %v", time.Since(startTime))
128+
log.Log(rt.INFO, "All workers done after %v", time.Since(startTime).Round(100*time.Millisecond))
131129
return nil
132130
})
133131

@@ -148,7 +146,7 @@ func RunMigration(ctx context.Context, cfg Config, cache MigrationCache, store c
148146
}
149147
resultCount++
150148
}
151-
log.Log(rt.INFO, "Result writer wrote %d results to state tree after %v", resultCount, time.Since(startTime))
149+
log.Log(rt.INFO, "Result writer wrote %d results to state tree after %v", resultCount, time.Since(startTime).Round(100*time.Millisecond))
152150
return nil
153151
})
154152

@@ -197,7 +195,7 @@ func RunMigration(ctx context.Context, cfg Config, cache MigrationCache, store c
197195

198196
elapsed := time.Since(startTime)
199197
rate := float64(doneCount) / elapsed.Seconds()
200-
log.Log(rt.INFO, "All %d done after %v (%.0f/s)", doneCount, elapsed, rate)
198+
log.Log(rt.INFO, "All %d done after %v (%.0f/s)", doneCount, elapsed.Round(100*time.Millisecond), rate)
201199

202200
return actorsOut, nil
203201
}

0 commit comments

Comments
 (0)