Skip to content

Commit

Permalink
e2: remove overlapped files only after merge (#10487)
Browse files Browse the repository at this point in the history
Otherwise: if start after `kill -9` in the middle of merge - may remove
small files of 1 type of file, but leave small files of another type of
files (which merge was not finished) - and leave node in un-mergable
state: #10485

---------

Co-authored-by: awskii <[email protected]>
  • Loading branch information
AskAlexSharov and awskii authored May 28, 2024
1 parent d3af203 commit 608a940
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
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

0 comments on commit 608a940

Please sign in to comment.