4
4
"context"
5
5
"errors"
6
6
"fmt"
7
- "os"
8
7
"slices"
9
- "strconv"
10
8
"sync"
11
9
"sync/atomic"
12
10
"time"
@@ -425,22 +423,6 @@ func (s *Store[H]) DeleteTo(ctx context.Context, to uint64) error {
425
423
return nil
426
424
}
427
425
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
-
444
426
func (s * Store [H ]) deleteRange (ctx context.Context , from , to uint64 ) (rerr error ) {
445
427
s .onDeleteMu .Lock ()
446
428
onDelete := slices .Clone (s .onDelete )
@@ -455,8 +437,11 @@ func (s *Store[H]) deleteRange(ctx context.Context, from, to uint64) (rerr error
455
437
defer func () {
456
438
// make new context to always save progress
457
439
ctx := context .Background ()
440
+
441
+ log .Infow ("deleted headers" , "from_height" , from , "to_height" , to )
458
442
newTailHeight := to
459
443
if rerr != nil {
444
+ log .Warnw ("partial delete with error" , "expected_to_height" , newTailHeight , "actual_to_height" , height , "err" , err )
460
445
newTailHeight = height
461
446
}
462
447
@@ -470,7 +455,7 @@ func (s *Store[H]) deleteRange(ctx context.Context, from, to uint64) (rerr error
470
455
}
471
456
}()
472
457
473
- for ; height < to ; height ++ {
458
+ for i := 0 ; height < to ; height ++ {
474
459
hash , err := s .heightIndex .HashByHeight (ctx , height , false )
475
460
if errors .Is (err , datastore .ErrNotFound ) {
476
461
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
496
481
s .cache .Remove (hash .String ())
497
482
s .heightIndex .cache .Remove (height )
498
483
s .pending .DeleteRange (height , height + 1 )
484
+
485
+ if i % 100000 == 0 {
486
+ log .Debug ("deleted %d headers" , i )
487
+ }
488
+
489
+ i ++
499
490
}
500
491
501
- log .Infow ("deleted headers" , "from_height" , from , "to_height" , to )
502
492
return nil
503
493
}
504
494
@@ -516,6 +506,8 @@ func (s *Store[H]) setTail(ctx context.Context, batch datastore.Batch, to uint64
516
506
if err := writeHeaderHashTo (ctx , batch , newTail , tailKey ); err != nil {
517
507
return fmt .Errorf ("writing tailKey in batch: %w" , err )
518
508
}
509
+ log .Infow ("new tail" , "height" , newTail .Height (), "hash" , newTail .Hash ())
510
+ s .metrics .newTail (newTail .Height ())
519
511
520
512
// update head as well, if delete went over it
521
513
head , err := s .Head (ctx )
0 commit comments