core/blockchain: export progress

This commit is contained in:
Raghav Sood 2018-06-25 11:33:30 +12:00
parent eaff89291c
commit abec756be2
No known key found for this signature in database
GPG key ID: 847EE905DC789D4D
2 changed files with 17 additions and 3 deletions

View file

@ -94,7 +94,8 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
Requires a first argument of the file to write to. Requires a first argument of the file to write to.
Optional second and third arguments control the first and Optional second and third arguments control the first and
last block to write. In this mode, the file will be appended last block to write. In this mode, the file will be appended
if already existing.`, if already existing. If the file ends with .gz, the output will
be gzipped.`,
} }
importPreimagesCommand = cli.Command{ importPreimagesCommand = cli.Command{
Action: utils.MigrateFlags(importPreimages), Action: utils.MigrateFlags(importPreimages),

View file

@ -448,10 +448,23 @@ 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)
} }
log.Info("Exporting batch of blocks", "count", last-first+1) batchSize := last - first + 1
log.Info("Exporting batch of blocks", "count", batchSize)
exportTimeElapsed := mclock.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)
} }
@ -1203,7 +1216,7 @@ type insertStats struct {
startTime mclock.AbsTime startTime mclock.AbsTime
} }
// statsReportLimit is the time limit during import after which we always print // statsReportLimit is the time limit during import and export after which we always print
// out progress. This avoids the user wondering what's going on. // out progress. This avoids the user wondering what's going on.
const statsReportLimit = 8 * time.Second const statsReportLimit = 8 * time.Second