core: polish up chain export progress report a bit

This commit is contained in:
Péter Szilágyi 2018-07-26 14:23:18 +03:00
parent abec756be2
commit e5e8da9661
No known key found for this signature in database
GPG key ID: E9AE538CEDF8293D

View file

@ -448,30 +448,21 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
if first > last { if first > last {
return fmt.Errorf("export failed: first (%d) is greater than last (%d)", first, last) return fmt.Errorf("export failed: first (%d) is greater than last (%d)", first, last)
} }
batchSize := last - first + 1 log.Info("Exporting batch of blocks", "count", last-first+1)
log.Info("Exporting batch of blocks", "count", batchSize)
exportTimeElapsed := mclock.Now() start, reported := time.Now(), time.Now()
for nr := first; nr <= last; nr++ { for nr := first; nr <= last; nr++ {
block := bc.GetBlockByNumber(nr) block := bc.GetBlockByNumber(nr)
var (
now = mclock.Now()
elapsed = time.Duration(now) - time.Duration(exportTimeElapsed)
)
if elapsed >= statsReportLimit {
exportedBlocks := block.NumberU64() - first
log.Info("Exporting blocks", "exported", exportedBlocks, "elapsed", common.PrettyDuration(elapsed))
exportTimeElapsed = mclock.Now()
}
if block == nil { if block == nil {
return fmt.Errorf("export failed on #%d: not found", nr) return fmt.Errorf("export failed on #%d: not found", nr)
} }
if err := block.EncodeRLP(w); err != nil { if err := block.EncodeRLP(w); err != nil {
return err return err
} }
if time.Since(reported) >= statsReportLimit {
log.Info("Exporting blocks", "exported", block.NumberU64()-first, "elapsed", common.PrettyDuration(time.Since(start)))
reported = time.Now()
}
} }
return nil return nil
@ -1216,8 +1207,8 @@ type insertStats struct {
startTime mclock.AbsTime startTime mclock.AbsTime
} }
// statsReportLimit is the time limit during import and export after which we always print // statsReportLimit is the time limit during import and export after which we
// out progress. This avoids the user wondering what's going on. // always print out progress. This avoids the user wondering what's going on.
const statsReportLimit = 8 * time.Second const statsReportLimit = 8 * time.Second
// report prints statistics if some number of blocks have been processed // report prints statistics if some number of blocks have been processed