forked from pingcap/dumpling
/
status.go
61 lines (51 loc) · 1.67 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
package export
import (
"fmt"
"time"
tcontext "github.com/dbakit/dumpling/v5/context"
"github.com/docker/go-units"
"go.uber.org/zap"
)
const logProgressTick = 2 * time.Minute
func (d *Dumper) runLogProgress(tctx *tcontext.Context) {
conf := d.conf
totalTables := float64(calculateTableCount(conf.Tables))
logProgressTicker := time.NewTicker(logProgressTick)
lastCheckpoint := time.Now()
lastBytes := float64(0)
defer logProgressTicker.Stop()
for {
select {
case <-tctx.Done():
tctx.L().Debug("stopping log progress")
return
case <-logProgressTicker.C:
nanoseconds := float64(time.Since(lastCheckpoint).Nanoseconds())
completedTables := ReadCounter(finishedTablesCounter, conf.Labels)
finishedBytes := ReadGauge(finishedSizeGauge, conf.Labels)
finishedRows := ReadGauge(finishedRowsGauge, conf.Labels)
estimateTotalRows := ReadCounter(estimateTotalRowsCounter, conf.Labels)
tctx.L().Info("progress",
zap.String("tables", fmt.Sprintf("%.0f/%.0f (%.1f%%)", completedTables, totalTables, completedTables/totalTables*100)),
zap.String("finished rows", fmt.Sprintf("%.0f", finishedRows)),
zap.String("estimate total rows", fmt.Sprintf("%.0f", estimateTotalRows)),
zap.String("finished size", units.HumanSize(finishedBytes)),
zap.Float64("average speed(MiB/s)", (finishedBytes-lastBytes)/(1048576e-9*nanoseconds)),
)
lastCheckpoint = time.Now()
lastBytes = finishedBytes
}
}
}
func calculateTableCount(m DatabaseTables) int {
cnt := 0
for _, tables := range m {
for _, table := range tables {
if table.Type == TableTypeBase {
cnt++
}
}
}
return cnt
}