diff --git a/turbo/snapshotsync/merger.go b/turbo/snapshotsync/merger.go index 6db489f04c2..a842ba81207 100644 --- a/turbo/snapshotsync/merger.go +++ b/turbo/snapshotsync/merger.go @@ -236,9 +236,6 @@ func (m *Merger) integrateMergedDirtyFiles(snapshots *RoSnapshots, in, out map[s for _, delSeg := range delSegs { dirtySegments.Delete(delSeg) delSeg.canDelete.Store(true) - if delSeg.refcount.Load() == 0 { - delSeg.closeAndRemoveFiles() - } } } } diff --git a/turbo/snapshotsync/snapshots.go b/turbo/snapshotsync/snapshots.go index 47e97c7fb83..c46d4a5ff02 100644 --- a/turbo/snapshotsync/snapshots.go +++ b/turbo/snapshotsync/snapshots.go @@ -1291,9 +1291,6 @@ func (s *RoSnapshots) delete(fileName string) error { continue } sn.canDelete.Store(true) - if sn.refcount.Load() == 0 { - sn.closeAndRemoveFiles() - } delSeg = sn dirtySegments = s.dirty[t] findDelSeg = false @@ -1314,6 +1311,10 @@ func (s *RoSnapshots) Delete(fileName string) error { if s == nil { return nil } + + v := s.View() + defer v.Close() + defer s.recalcVisibleFiles() if err := s.delete(fileName); err != nil { return fmt.Errorf("can't delete file: %w", err)