Skip to content

Commit 50f8c72

Browse files
committed
better logging
1 parent 406e53f commit 50f8c72

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

store/store.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"os"
87
"slices"
9-
"strconv"
108
"sync"
119
"sync/atomic"
1210
"time"
@@ -425,22 +423,6 @@ func (s *Store[H]) DeleteTo(ctx context.Context, to uint64) error {
425423
return nil
426424
}
427425

428-
var maxHeadersLoadedPerDelete uint64 = 1024
429-
430-
func init() {
431-
v, ok := os.LookupEnv("HEADER_MAX_LOAD_PER_DELETE")
432-
if !ok {
433-
return
434-
}
435-
436-
max, err := strconv.Atoi(v)
437-
if err != nil {
438-
panic(err)
439-
}
440-
441-
maxHeadersLoadedPerDelete = uint64(max)
442-
}
443-
444426
func (s *Store[H]) deleteRange(ctx context.Context, from, to uint64) (rerr error) {
445427
s.onDeleteMu.Lock()
446428
onDelete := slices.Clone(s.onDelete)
@@ -455,8 +437,11 @@ func (s *Store[H]) deleteRange(ctx context.Context, from, to uint64) (rerr error
455437
defer func() {
456438
// make new context to always save progress
457439
ctx := context.Background()
440+
441+
log.Infow("deleted headers", "from_height", from, "to_height", to)
458442
newTailHeight := to
459443
if rerr != nil {
444+
log.Warnw("partial delete with error", "expected_to_height", newTailHeight, "actual_to_height", height, "err", err)
460445
newTailHeight = height
461446
}
462447

@@ -470,7 +455,7 @@ func (s *Store[H]) deleteRange(ctx context.Context, from, to uint64) (rerr error
470455
}
471456
}()
472457

473-
for ; height < to; height++ {
458+
for i := 0; height < to; height++ {
474459
hash, err := s.heightIndex.HashByHeight(ctx, height, false)
475460
if errors.Is(err, datastore.ErrNotFound) {
476461
log.Warnf("attempt to delete header that's not found", "height", height)
@@ -496,9 +481,14 @@ func (s *Store[H]) deleteRange(ctx context.Context, from, to uint64) (rerr error
496481
s.cache.Remove(hash.String())
497482
s.heightIndex.cache.Remove(height)
498483
s.pending.DeleteRange(height, height+1)
484+
485+
if i%100000 == 0 {
486+
log.Debug("deleted %d headers", i)
487+
}
488+
489+
i++
499490
}
500491

501-
log.Infow("deleted headers", "from_height", from, "to_height", to)
502492
return nil
503493
}
504494

@@ -516,6 +506,8 @@ func (s *Store[H]) setTail(ctx context.Context, batch datastore.Batch, to uint64
516506
if err := writeHeaderHashTo(ctx, batch, newTail, tailKey); err != nil {
517507
return fmt.Errorf("writing tailKey in batch: %w", err)
518508
}
509+
log.Infow("new tail", "height", newTail.Height(), "hash", newTail.Hash())
510+
s.metrics.newTail(newTail.Height())
519511

520512
// update head as well, if delete went over it
521513
head, err := s.Head(ctx)

0 commit comments

Comments
 (0)