Skip to content

Commit 948e781

Browse files
Blocks snaps - see 0 indices after reopen (#10219)
Cherry pick PR #10214 into the release Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com>
1 parent a1e1338 commit 948e781

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

cmd/rpcdaemon/cli/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
384384
allSnapshots.OptimisticReopenWithDB(db)
385385
allBorSnapshots.OptimisticalyReopenWithDB(db)
386386
allSnapshots.LogStat("remote")
387-
allBorSnapshots.LogStat("remote")
387+
allBorSnapshots.LogStat("bor:remote")
388388

389389
if agg, err = libstate.NewAggregator(ctx, cfg.Dirs.SnapHistory, cfg.Dirs.Tmp, config3.HistoryV3AggregationStep, db, logger); err != nil {
390390
return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("create aggregator: %w", err)
@@ -413,7 +413,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
413413
if err := allBorSnapshots.ReopenList(reply.BlocksFiles, true); err != nil {
414414
logger.Error("[bor snapshots] reopen", "err", err)
415415
} else {
416-
allBorSnapshots.LogStat("reopen")
416+
allBorSnapshots.LogStat("bor:reopen")
417417
}
418418

419419
_ = reply.HistoryFiles

turbo/app/snapshots_cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func openSnaps(ctx context.Context, cfg ethconfig.BlocksFreezing, dirs datadir.D
409409
return
410410
}
411411

412-
borSnaps.LogStat("open")
412+
borSnaps.LogStat("bor:open")
413413
agg = openAgg(ctx, dirs, chainDB, logger)
414414
err = chainDB.View(ctx, func(tx kv.Tx) error {
415415
ac := agg.BeginFilesRo()

turbo/snapshotsync/freezeblocks/block_snapshots.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/hex"
88
"errors"
99
"fmt"
10-
"math"
1110
"os"
1211
"path/filepath"
1312
"reflect"
@@ -312,8 +311,8 @@ func (s *RoSnapshots) BlocksAvailable() uint64 {
312311
func (s *RoSnapshots) LogStat(label string) {
313312
var m runtime.MemStats
314313
dbg.ReadMemStats(&m)
315-
s.logger.Info(fmt.Sprintf("[snapshots:%s] Blocks Stat", label),
316-
"blocks", fmt.Sprintf("%dk", (s.BlocksAvailable()+1)/1000),
314+
s.logger.Info(fmt.Sprintf("[snapshots:%s] Stat", label),
315+
"blocks", fmt.Sprintf("%dk", (s.SegmentsMax()+1)/1000),
317316
"indices", fmt.Sprintf("%dk", (s.IndicesMax()+1)/1000),
318317
"alloc", common2.ByteCount(m.Alloc), "sys", common2.ByteCount(m.Sys))
319318
}
@@ -386,29 +385,46 @@ func (s *RoSnapshots) EnableMadvNormal() *RoSnapshots {
386385
return s
387386
}
388387

388+
// minimax of existing indices
389389
func (s *RoSnapshots) idxAvailability() uint64 {
390-
_max := make([]uint64, len(s.Types()))
391-
i := 0
390+
// Use-Cases:
391+
// 1. developers can add new types in future. and users will not have files of this type
392+
// 2. some types are network-specific. example: borevents exists only on Bor-consensus networks
393+
// 3. user can manually remove 1 .idx file: `rm snapshots/v1-type1-0000-1000.idx`
394+
// 4. user can manually remove all .idx files of given type: `rm snapshots/*type1*.idx`
395+
// 5. file-types may have different height: 10 headers, 10 bodies, 9 trancasctions (for example if `kill -9` came during files building/merge). still need index all 3 types.
396+
amount := 0
397+
s.segments.Scan(func(segtype snaptype.Enum, value *segments) bool {
398+
if len(value.segments) == 0 || !s.HasType(segtype.Type()) {
399+
return true
400+
}
401+
amount++
402+
return true
403+
})
392404

405+
maximums := make([]uint64, amount)
406+
var i int
393407
s.segments.Scan(func(segtype snaptype.Enum, value *segments) bool {
408+
if len(value.segments) == 0 || !s.HasType(segtype.Type()) {
409+
return true
410+
}
411+
394412
for _, seg := range value.segments {
395413
if !seg.IsIndexed() {
396414
break
397415
}
398416

399-
_max[i] = seg.to - 1
417+
maximums[i] = seg.to - 1
400418
}
401419

402420
i++
403421
return true
404422
})
405423

406-
var _min uint64 = math.MaxUint64
407-
for _, maxEl := range _max {
408-
_min = cmp.Min(_min, maxEl)
424+
if len(maximums) == 0 {
425+
return 0
409426
}
410-
411-
return _min
427+
return slices.Min(maximums)
412428
}
413429

414430
// OptimisticReopenWithDB - optimistically open snapshots (ignoring error), useful at App startup because:

0 commit comments

Comments
 (0)