ethdb: add log

This commit is contained in:
Gary Rong 2025-03-28 11:38:34 +08:00
parent b474628f03
commit 86e3f1fc3a
2 changed files with 19 additions and 5 deletions

View file

@ -23,11 +23,11 @@ package leveldb
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/crypto"
"sync" "sync"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
@ -222,11 +222,18 @@ func (db *Database) DeleteRange(start, end []byte) error {
var ( var (
count int count int
ignored int
buff = crypto.NewKeccakState() buff = crypto.NewKeccakState()
) )
defer func() {
if ignored > 0 {
log.Info("Skipped entries from deletion", "number", ignored)
}
}()
for it.Next() && bytes.Compare(end, it.Key()) > 0 { for it.Next() && bytes.Compare(end, it.Key()) > 0 {
// Prevent deletion for trie nodes in hash mode // Prevent deletion for trie nodes in hash mode
if h := crypto.HashData(buff, it.Value()); h == common.BytesToHash(it.Key()) { if h := crypto.HashData(buff, it.Value()); h == common.BytesToHash(it.Key()) {
ignored++
continue continue
} }
count++ count++

View file

@ -360,11 +360,18 @@ func (d *Database) DeleteRange(start, end []byte) error {
var ( var (
count int count int
ignored int
buff = crypto.NewKeccakState() buff = crypto.NewKeccakState()
) )
defer func() {
if ignored > 0 {
log.Info("Skipped entries from deletion", "number", ignored)
}
}()
for it.Next() && bytes.Compare(end, it.Key()) > 0 { for it.Next() && bytes.Compare(end, it.Key()) > 0 {
// Prevent deletion for trie nodes in hash mode // Prevent deletion for trie nodes in hash mode
if h := crypto.HashData(buff, it.Value()); h == common.BytesToHash(it.Key()) { if h := crypto.HashData(buff, it.Value()); h == common.BytesToHash(it.Key()) {
ignored++
continue continue
} }
count++ count++