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

e2: remove overlapped files only after merge #10487

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func (s *RoSnapshots) closeWhatNotInList(l []string) {
})
}

func (s *RoSnapshots) removeOverlaps() error {
func (s *RoSnapshots) removeOverlapsAfterMerge() error {
s.lockSegments()
defer s.unlockSegments()

Expand Down Expand Up @@ -1260,8 +1260,6 @@ func (br *BlockRetire) retireBlocks(ctx context.Context, minBlockNum uint64, max
return ok, fmt.Errorf("DumpBlocks: %w", err)
}

snapshots.removeOverlaps()

if err := snapshots.ReopenFolder(); err != nil {
return ok, fmt.Errorf("reopen: %w", err)
}
Expand Down Expand Up @@ -1297,6 +1295,9 @@ func (br *BlockRetire) retireBlocks(ctx context.Context, minBlockNum uint64, max
return ok, err
}

if err := snapshots.removeOverlapsAfterMerge(); err != nil {
return ok, err
}
return ok, nil
}

Expand Down
2 changes: 1 addition & 1 deletion turbo/snapshotsync/freezeblocks/block_snapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func TestRemoveOverlaps(t *testing.T) {
require.NoError(err)
require.Equal(45, len(list))

s.removeOverlaps()
s.removeOverlapsAfterMerge()

list, err = snaptype.Segments(s.dir)
require.NoError(err)
Expand Down
19 changes: 13 additions & 6 deletions turbo/snapshotsync/freezeblocks/bor_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,21 @@ func (br *BlockRetire) retireBorBlocks(ctx context.Context, minBlockNum uint64,
}

err := merger.Merge(ctx, &snapshots.RoSnapshots, borsnaptype.BorSnapshotTypes(), rangesToMerge, snapshots.Dir(), true /* doIndex */, onMerge, onDelete)

if err != nil {
return blocksRetired, err
}

{
files, _, err := typedSegments(br.borSnapshots().dir, br.borSnapshots().segmentsMin.Load(), borsnaptype.BorSnapshotTypes(), false)
if err != nil {
return blocksRetired, err
}

// this is one off code to fix an issue in 2.49.x->2.52.x which missed
// removal of intermediate segments after a merge operation
removeBorOverlapsAfterMerge(br.borSnapshots().dir, files, br.borSnapshots().BlocksAvailable())
}

return blocksRetired, nil
}

Expand Down Expand Up @@ -138,7 +149,7 @@ func (s *BorRoSnapshots) Ranges() []Range {

// this is one off code to fix an issue in 2.49.x->2.52.x which missed
// removal of intermediate segments after a merge operation
func removeBorOverlaps(dir string, active []snaptype.FileInfo, max uint64) {
func removeBorOverlapsAfterMerge(dir string, active []snaptype.FileInfo, max uint64) {
list, err := snaptype.Segments(dir)

if err != nil {
Expand Down Expand Up @@ -204,10 +215,6 @@ func (s *BorRoSnapshots) ReopenFolder() error {
return err
}

// this is one off code to fix an issue in 2.49.x->2.52.x which missed
// removal of intermediate segments after a merge operation
removeBorOverlaps(s.dir, files, s.BlocksAvailable())

list := make([]string, 0, len(files))
for _, f := range files {
_, fName := filepath.Split(f.Path)
Expand Down
Loading