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

seg: don't reopen files #12362

Merged
merged 40 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e729c1f
save
AskAlexSharov Oct 16, 2024
9c0fe92
save
AskAlexSharov Oct 16, 2024
8c3eeb4
save
AskAlexSharov Oct 16, 2024
30be59c
save
AskAlexSharov Oct 16, 2024
152632f
save
AskAlexSharov Oct 16, 2024
d903430
save
AskAlexSharov Oct 16, 2024
333a4fe
save
AskAlexSharov Oct 16, 2024
74161df
save
AskAlexSharov Oct 17, 2024
9e2c1c1
save
AskAlexSharov Oct 17, 2024
f582712
save
AskAlexSharov Oct 17, 2024
c50a0c9
save
AskAlexSharov Oct 17, 2024
ab8f414
save
AskAlexSharov Oct 17, 2024
6db4f42
save
AskAlexSharov Oct 17, 2024
1726218
save
AskAlexSharov Oct 17, 2024
8beff9a
Merge branch 'main' into rpcdaemon_dont_open_uncomplete
AskAlexSharov Oct 17, 2024
690ae7b
save
AskAlexSharov Oct 17, 2024
c1071e2
save
AskAlexSharov Oct 17, 2024
1f962b1
save
AskAlexSharov Oct 17, 2024
e47c663
save
AskAlexSharov Oct 17, 2024
0678cee
save
AskAlexSharov Oct 17, 2024
9a69904
save
AskAlexSharov Oct 17, 2024
80586ac
save
AskAlexSharov Oct 17, 2024
678ee95
save
AskAlexSharov Oct 18, 2024
29ba71d
save
AskAlexSharov Oct 18, 2024
7c00ba5
save
AskAlexSharov Oct 18, 2024
fff9555
Merge branch 'main' into rpcdaemon_dont_open_uncomplete
AskAlexSharov Oct 18, 2024
e7c0634
save
AskAlexSharov Oct 18, 2024
a0ffe2a
save
AskAlexSharov Oct 18, 2024
79f57b8
save
AskAlexSharov Oct 18, 2024
d5f6c3f
save
AskAlexSharov Oct 18, 2024
ad65988
save
AskAlexSharov Oct 18, 2024
66fed7b
save
AskAlexSharov Oct 18, 2024
d145ab8
Merge branch 'rpcdaemon_dont_open_uncomplete' into rpcdaemon_dont_ope…
AskAlexSharov Oct 18, 2024
f3e05fc
save
AskAlexSharov Oct 18, 2024
29259b4
save
AskAlexSharov Oct 18, 2024
028e2d7
save
AskAlexSharov Oct 18, 2024
d66c834
save
AskAlexSharov Oct 18, 2024
21da3b5
save
AskAlexSharov Oct 18, 2024
fe8b74e
save
AskAlexSharov Oct 18, 2024
f079aa1
save
AskAlexSharov Oct 18, 2024
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
57 changes: 42 additions & 15 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ func (s *DirtySegment) Version() snaptype.Version {
return s.version
}

func (s *DirtySegment) Indexed() bool {
if s.Decompressor == nil {
return false
}
if len(s.indexes) != len(s.Type().Indexes()) {
return false
}
for _, idx := range s.indexes {
if idx == nil {
return false
}
}
return true
}

func (s *DirtySegment) Index(index ...snaptype.Index) *recsplit.Index {
if len(index) == 0 {
index = []snaptype.Index{{}}
Expand Down Expand Up @@ -276,10 +291,9 @@ func (s *DirtySegment) isSubSetOf(j *DirtySegment) bool {
}

func (s *DirtySegment) reopenSeg(dir string) (err error) {
if s.refcount.Load() > 0 {
return
if s.Decompressor != nil {
return nil
}
s.closeSeg()
s.Decompressor, err = seg.NewDecompressor(filepath.Join(dir, s.FileName()))
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, s.FileName())
Expand Down Expand Up @@ -350,23 +364,24 @@ func (s *DirtySegment) reopenIdxIfNeed(dir string, optimistic bool) (err error)
}

func (s *DirtySegment) reopenIdx(dir string) (err error) {
if s.refcount.Load() > 0 {
return nil
}

s.closeIdx()
if s.Decompressor == nil {
return nil
}
for len(s.indexes) < len(s.Type().Indexes()) {
s.indexes = append(s.indexes, nil)
}

for _, fileName := range s.Type().IdxFileNames(s.version, s.from, s.to) {
index, err := recsplit.OpenIndex(filepath.Join(dir, fileName))
for i, fileName := range s.Type().IdxFileNames(s.version, s.from, s.to) {
if s.indexes[i] != nil {
continue
}

index, err := recsplit.OpenIndex(filepath.Join(dir, fileName))
if err != nil {
return fmt.Errorf("%w, fileName: %s", err, fileName)
}

s.indexes = append(s.indexes, index)
s.indexes[i] = index
}

return nil
Expand Down Expand Up @@ -609,12 +624,11 @@ func (s *RoSnapshots) recalcVisibleFiles() {
if seg.canDelete.Load() {
continue
}
if seg.Decompressor == nil {
if !seg.Indexed() {
continue
}
if seg.indexes == nil {
break
}

//protect from overlaps overlaps
for len(newVisibleSegments) > 0 && newVisibleSegments[len(newVisibleSegments)-1].src.isSubSetOf(seg) {
newVisibleSegments[len(newVisibleSegments)-1].src = nil
newVisibleSegments = newVisibleSegments[:len(newVisibleSegments)-1]
Expand All @@ -629,6 +643,18 @@ func (s *RoSnapshots) recalcVisibleFiles() {
return true
})

// protect from gaps
if len(newVisibleSegments) > 0 {
prevEnd := newVisibleSegments[0].from
for i, seg := range newVisibleSegments {
if seg.from != prevEnd {
newVisibleSegments = newVisibleSegments[:i] //remove tail if see gap
break
}
prevEnd = seg.to
}
}

value.VisibleSegments = newVisibleSegments
var to uint64
if len(newVisibleSegments) > 0 {
Expand All @@ -638,6 +664,7 @@ func (s *RoSnapshots) recalcVisibleFiles() {
return true
})

// all types must have same hight
minMaxVisibleBlock := slices.Min(maxVisibleBlocks)
s.segments.Scan(func(segtype snaptype.Enum, value *segments) bool {
if minMaxVisibleBlock == 0 {
Expand Down
6 changes: 2 additions & 4 deletions turbo/snapshotsync/freezeblocks/block_snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ import (
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/turbo/testlog"

"github.com/erigontech/erigon-lib/chain/networkname"
"github.com/erigontech/erigon-lib/chain/snapcfg"
"github.com/erigontech/erigon-lib/downloader/snaptype"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon-lib/recsplit"
"github.com/erigontech/erigon-lib/seg"

"github.com/erigontech/erigon/common/math"
coresnaptype "github.com/erigontech/erigon/core/snaptype"
"github.com/erigontech/erigon/eth/ethconfig"
"github.com/erigontech/erigon/params"
"github.com/erigontech/erigon/turbo/testlog"
)

func createTestSegmentFile(t *testing.T, from, to uint64, name snaptype.Enum, dir string, version snaptype.Version, logger log.Logger) {
Expand Down
Loading