From c406c8a66a43bce977f20c00809b8fa0986781e3 Mon Sep 17 00:00:00 2001 From: eastorski Date: Tue, 17 Dec 2024 16:03:18 +0000 Subject: [PATCH] Fixed snapshot read from disk --- turbo/snapshotsync/snapshots.go | 40 +++++++++------------------------ 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/turbo/snapshotsync/snapshots.go b/turbo/snapshotsync/snapshots.go index c46d4a5ff02..6ecdc947dcf 100644 --- a/turbo/snapshotsync/snapshots.go +++ b/turbo/snapshotsync/snapshots.go @@ -35,7 +35,6 @@ import ( "github.com/erigontech/erigon-lib/common/background" "github.com/erigontech/erigon-lib/common/datadir" "github.com/erigontech/erigon-lib/common/dbg" - dir2 "github.com/erigontech/erigon-lib/common/dir" "github.com/erigontech/erigon-lib/diagnostics" "github.com/erigontech/erigon-lib/downloader/snaptype" "github.com/erigontech/erigon-lib/log/v3" @@ -56,6 +55,10 @@ type SortedRange interface { // NoOverlaps - keep largest ranges and avoid overlap func NoOverlaps[T SortedRange](in []T) (res []T) { + if len(in) == 1 { + return in + } + for i := 0; i < len(in); i++ { r := in[i] iFrom, iTo := r.GetRange() @@ -83,6 +86,10 @@ func NoGaps[T SortedRange](in []T) (out []T, missingRanges []Range) { if len(in) == 0 { return nil, nil } + if len(in) == 1 { + return in, nil + } + prevTo, _ := in[0].GetRange() for _, f := range in { from, to := f.GetRange() @@ -980,10 +987,6 @@ func (s *RoSnapshots) InitSegments(fileNames []string) error { } func TypedSegments(dir string, minBlock uint64, types []snaptype.Type, allowGaps bool) (res []snaptype.FileInfo, missingSnapshots []Range, err error) { - segmentsTypeCheck := func(dir string, in []snaptype.FileInfo) (res []snaptype.FileInfo) { - return typeOfSegmentsMustExist(dir, in, types) - } - list, err := snaptype.Segments(dir) if err != nil { @@ -1002,10 +1005,11 @@ func TypedSegments(dir string, minBlock uint64, types []snaptype.Type, allowGaps } if allowGaps { - l = NoOverlaps(segmentsTypeCheck(dir, l)) + l = NoOverlaps(l) } else { - l, m = NoGaps(NoOverlaps(segmentsTypeCheck(dir, l))) + l, m = NoGaps(NoOverlaps(l)) } + if len(m) > 0 { lst := m[len(m)-1] log.Debug("[snapshots] see gap", "type", segType, "from", lst.from) @@ -1619,28 +1623,6 @@ func sendDiagnostics(startIndexingTime time.Time, indexPercent map[string]int, a }) } -func typeOfSegmentsMustExist(dir string, in []snaptype.FileInfo, types []snaptype.Type) (res []snaptype.FileInfo) { -MainLoop: - for _, f := range in { - if f.From == f.To { - continue - } - for _, t := range types { - p := filepath.Join(dir, snaptype.SegmentFileName(f.Version, f.From, f.To, t.Enum())) - exists, err := dir2.FileExist(p) - if err != nil { - log.Debug("[snapshots] FileExist error", "err", err, "path", p) - continue MainLoop - } - if !exists { - continue MainLoop - } - res = append(res, f) - } - } - return res -} - func removeOldFiles(toDel []string, snapDir string) { for _, f := range toDel { _ = os.Remove(f)