Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed snapshot read from disk #13144

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions turbo/snapshotsync/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading