From 73358fab1b46dccc13fe54efad80f9b8f4b07956 Mon Sep 17 00:00:00 2001
From: Alex Sharov <AskAlexSharov@gmail.com>
Date: Sun, 1 Nov 2020 15:28:11 +0700
Subject: [PATCH] up master (#1332)

---
 ethdb/mutation.go | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/ethdb/mutation.go b/ethdb/mutation.go
index f09ff2a814..8f794cfffe 100644
--- a/ethdb/mutation.go
+++ b/ethdb/mutation.go
@@ -7,11 +7,13 @@ import (
 	"strings"
 	"sync"
 	"sync/atomic"
+	"time"
 	"unsafe"
 
 	"github.com/c2h5oh/datasize"
 	"github.com/google/btree"
 	"github.com/ledgerwatch/turbo-geth/common"
+	"github.com/ledgerwatch/turbo-geth/log"
 	"github.com/ledgerwatch/turbo-geth/metrics"
 )
 
@@ -200,6 +202,11 @@ func (m *mutation) doCommit(tx Tx) error {
 	var c Cursor
 	var innerErr error
 	var isEndOfBucket bool
+	logEvery := time.NewTicker(30 * time.Second)
+	defer logEvery.Stop()
+	count := 0
+	total := float64(m.puts.Len())
+
 	m.puts.Ascend(func(i btree.Item) bool {
 		mi := i.(*MutationItem)
 		if mi.table != prevTable {
@@ -233,6 +240,15 @@ func (m *mutation) doCommit(tx Tx) error {
 				return false
 			}
 		}
+
+		count++
+
+		select {
+		default:
+		case <-logEvery.C:
+			progress := fmt.Sprintf("%.1fM/%.1fM", float64(count)/1_000_000, total/1_000_000)
+			log.Info("Write to db", "progress", progress, "current table", mi.table)
+		}
 		return true
 	})
 	return innerErr
-- 
GitLab