mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core/rawdb, core/filtermaps: polish code
This commit is contained in:
parent
c825264e37
commit
d1590055c5
3 changed files with 14 additions and 14 deletions
|
|
@ -391,18 +391,18 @@ func (f *FilterMaps) safeDeleteWithLogs(deleteFn func(db ethdb.KeyValueStore, ha
|
|||
)
|
||||
switch err := deleteFn(f.db, f.hashScheme, func(deleted bool) bool {
|
||||
if deleted && !logPrinted || time.Since(lastLogPrinted) > time.Second*10 {
|
||||
log.Info(action+" in progress...", "elapsed", time.Since(start))
|
||||
log.Info(action+" in progress...", "elapsed", common.PrettyDuration(time.Since(start)))
|
||||
logPrinted, lastLogPrinted = true, time.Now()
|
||||
}
|
||||
return stopCb()
|
||||
}); err {
|
||||
case nil:
|
||||
}); {
|
||||
case err == nil:
|
||||
if logPrinted {
|
||||
log.Info(action+" finished", "elapsed", time.Since(start))
|
||||
log.Info(action+" finished", "elapsed", common.PrettyDuration(time.Since(start)))
|
||||
}
|
||||
return nil
|
||||
case rawdb.ErrDeleteRangeInterrupted:
|
||||
log.Warn(action+" interrupted", "elapsed", time.Since(start))
|
||||
case errors.Is(err, rawdb.ErrDeleteRangeInterrupted):
|
||||
log.Warn(action+" interrupted", "elapsed", common.PrettyDuration(time.Since(start)))
|
||||
return err
|
||||
default:
|
||||
log.Error(action+" failed", "error", err)
|
||||
|
|
@ -759,7 +759,7 @@ func (f *FilterMaps) deleteTailEpoch(epoch uint32) (bool, error) {
|
|||
if f.cleanedEpochsBefore > epoch {
|
||||
f.cleanedEpochsBefore = epoch
|
||||
}
|
||||
if err == rawdb.ErrDeleteRangeInterrupted {
|
||||
if errors.Is(err, rawdb.ErrDeleteRangeInterrupted) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ func ReadFilterMapLastBlock(db ethdb.KeyValueReader, mapIndex uint32) (uint64, c
|
|||
return 0, common.Hash{}, err
|
||||
}
|
||||
if len(enc) != 40 {
|
||||
return 0, common.Hash{}, errors.New("Invalid block number and id encoding")
|
||||
return 0, common.Hash{}, errors.New("invalid block number and id encoding")
|
||||
}
|
||||
var id common.Hash
|
||||
copy(id[:], enc[8:])
|
||||
|
|
@ -404,7 +404,7 @@ func ReadBlockLvPointer(db ethdb.KeyValueReader, blockNumber uint64) (uint64, er
|
|||
return 0, err
|
||||
}
|
||||
if len(encPtr) != 8 {
|
||||
return 0, errors.New("Invalid log value pointer encoding")
|
||||
return 0, errors.New("invalid log value pointer encoding")
|
||||
}
|
||||
return binary.BigEndian.Uint64(encPtr), nil
|
||||
}
|
||||
|
|
@ -490,7 +490,7 @@ func DeleteFilterMapsDb(db ethdb.KeyValueStore, hashScheme bool, stopCallback fu
|
|||
return deletePrefixRange(db, []byte(filterMapsPrefix), hashScheme, stopCallback)
|
||||
}
|
||||
|
||||
// DeleteFilterMapsDb removes the old bloombits database and the associated
|
||||
// DeleteBloomBitsDb removes the old bloombits database and the associated
|
||||
// chain indexer database.
|
||||
func DeleteBloomBitsDb(db ethdb.KeyValueStore, hashScheme bool, stopCallback func(bool) bool) error {
|
||||
if err := deletePrefixRange(db, bloomBitsPrefix, hashScheme, stopCallback); err != nil {
|
||||
|
|
|
|||
|
|
@ -627,10 +627,10 @@ func SafeDeleteRange(db ethdb.KeyValueStore, start, end []byte, hashScheme bool,
|
|||
if !hashScheme {
|
||||
// delete entire range; use fast native range delete on pebble db
|
||||
for {
|
||||
switch err := db.DeleteRange(start, end); err {
|
||||
case nil:
|
||||
switch err := db.DeleteRange(start, end); {
|
||||
case err == nil:
|
||||
return nil
|
||||
case ethdb.ErrTooManyKeys:
|
||||
case errors.Is(err, ethdb.ErrTooManyKeys):
|
||||
if stopCallback(true) {
|
||||
return ErrDeleteRangeInterrupted
|
||||
}
|
||||
|
|
@ -650,7 +650,7 @@ func SafeDeleteRange(db ethdb.KeyValueStore, start, end []byte, hashScheme bool,
|
|||
it := db.NewIterator(nil, start)
|
||||
defer func() {
|
||||
it.Release() // it might be replaced during the process
|
||||
log.Debug("SafeDeleteRange finished", "deleted", deleted, "skipped", skipped, "elapsed", time.Since(startTime))
|
||||
log.Debug("SafeDeleteRange finished", "deleted", deleted, "skipped", skipped, "elapsed", common.PrettyDuration(time.Since(startTime)))
|
||||
}()
|
||||
|
||||
for it.Next() && bytes.Compare(end, it.Key()) > 0 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue