print compaction progress (#784)

This commit is contained in:
Alex Sharov 2020-07-26 00:18:45 +07:00 committed by GitHub
parent d05cfa22f6
commit 5f171a550f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,8 +4,12 @@ import (
"context"
"fmt"
"os"
"path"
"sync"
"time"
"github.com/ledgerwatch/lmdb-go/lmdb"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/core"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync"
@ -187,9 +191,41 @@ func copyCompact() error {
if err := env.SetMapSize(ethdb.LMDBMapSize); err != nil {
return err
}
f, err := os.Stat(path.Join(from, "data.mdb"))
if err != nil {
return err
}
ctx, stopLogging := context.WithCancel(context.Background())
defer stopLogging()
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case <-ctx.Done():
return
default:
}
f2, err := os.Stat(path.Join(to, "data.mdb"))
if err != nil {
log.Error("Progress check failed", "err", err)
return
}
log.Info("Progress", "done", common.StorageSize(f2.Size()), "from", common.StorageSize(f.Size()))
time.Sleep(20 * time.Second)
}
}()
if err := env.CopyFlag(to, lmdb.CopyCompact); err != nil {
return fmt.Errorf("%w, from: %s, to: %s", err, from, to)
}
stopLogging()
wg.Wait()
if err := os.Rename(from, backup); err != nil {
return err
}