diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index ab48c4c1326..dd3c917d50e 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -384,7 +384,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger allSnapshots.OptimisticReopenWithDB(db) allBorSnapshots.OptimisticalyReopenWithDB(db) allSnapshots.LogStat("remote") - allBorSnapshots.LogStat("remote") + allBorSnapshots.LogStat("bor:remote") if agg, err = libstate.NewAggregator(ctx, cfg.Dirs.SnapHistory, cfg.Dirs.Tmp, config3.HistoryV3AggregationStep, db, logger); err != nil { 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 if err := allBorSnapshots.ReopenList(reply.BlocksFiles, true); err != nil { logger.Error("[bor snapshots] reopen", "err", err) } else { - allBorSnapshots.LogStat("reopen") + allBorSnapshots.LogStat("bor:reopen") } _ = reply.HistoryFiles diff --git a/turbo/app/snapshots_cmd.go b/turbo/app/snapshots_cmd.go index ad4b2770a95..ae7ec3b30d0 100644 --- a/turbo/app/snapshots_cmd.go +++ b/turbo/app/snapshots_cmd.go @@ -409,7 +409,7 @@ func openSnaps(ctx context.Context, cfg ethconfig.BlocksFreezing, dirs datadir.D return } - borSnaps.LogStat("open") + borSnaps.LogStat("bor:open") agg = openAgg(ctx, dirs, chainDB, logger) err = chainDB.View(ctx, func(tx kv.Tx) error { ac := agg.BeginFilesRo() diff --git a/turbo/snapshotsync/freezeblocks/block_snapshots.go b/turbo/snapshotsync/freezeblocks/block_snapshots.go index 880c0b9ef96..03c22dd9eb8 100644 --- a/turbo/snapshotsync/freezeblocks/block_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/block_snapshots.go @@ -7,7 +7,6 @@ import ( "encoding/hex" "errors" "fmt" - "math" "os" "path/filepath" "reflect" @@ -312,8 +311,8 @@ func (s *RoSnapshots) BlocksAvailable() uint64 { func (s *RoSnapshots) LogStat(label string) { var m runtime.MemStats dbg.ReadMemStats(&m) - s.logger.Info(fmt.Sprintf("[snapshots:%s] Blocks Stat", label), - "blocks", fmt.Sprintf("%dk", (s.BlocksAvailable()+1)/1000), + s.logger.Info(fmt.Sprintf("[snapshots:%s] Stat", label), + "blocks", fmt.Sprintf("%dk", (s.SegmentsMax()+1)/1000), "indices", fmt.Sprintf("%dk", (s.IndicesMax()+1)/1000), "alloc", common2.ByteCount(m.Alloc), "sys", common2.ByteCount(m.Sys)) } @@ -386,29 +385,46 @@ func (s *RoSnapshots) EnableMadvNormal() *RoSnapshots { return s } +// minimax of existing indices func (s *RoSnapshots) idxAvailability() uint64 { - _max := make([]uint64, len(s.Types())) - i := 0 + // Use-Cases: + // 1. developers can add new types in future. and users will not have files of this type + // 2. some types are network-specific. example: borevents exists only on Bor-consensus networks + // 3. user can manually remove 1 .idx file: `rm snapshots/v1-type1-0000-1000.idx` + // 4. user can manually remove all .idx files of given type: `rm snapshots/*type1*.idx` + // 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. + amount := 0 + s.segments.Scan(func(segtype snaptype.Enum, value *segments) bool { + if len(value.segments) == 0 || !s.HasType(segtype.Type()) { + return true + } + amount++ + return true + }) + maximums := make([]uint64, amount) + var i int s.segments.Scan(func(segtype snaptype.Enum, value *segments) bool { + if len(value.segments) == 0 || !s.HasType(segtype.Type()) { + return true + } + for _, seg := range value.segments { if !seg.IsIndexed() { break } - _max[i] = seg.to - 1 + maximums[i] = seg.to - 1 } i++ return true }) - var _min uint64 = math.MaxUint64 - for _, maxEl := range _max { - _min = cmp.Min(_min, maxEl) + if len(maximums) == 0 { + return 0 } - - return _min + return slices.Min(maximums) } // OptimisticReopenWithDB - optimistically open snapshots (ignoring error), useful at App startup because: