diff --git a/state/domain.go b/state/domain.go index 9faac6b0e..ebd48f99c 100644 --- a/state/domain.go +++ b/state/domain.go @@ -28,7 +28,6 @@ import ( "path/filepath" "regexp" "strconv" - "strings" "sync/atomic" "time" @@ -126,7 +125,10 @@ func NewDomain( if err != nil { return nil, err } - d.scanStateFiles(files) + uselessFiles := d.scanStateFiles(files) + for _, f := range uselessFiles { + _ = os.Remove(filepath.Join(d.dir, f)) + } if err = d.openFiles(); err != nil { return nil, err } @@ -142,10 +144,9 @@ func (d *Domain) GetAndResetStats() DomainStats { return r } -func (d *Domain) scanStateFiles(files []fs.DirEntry) { +func (d *Domain) scanStateFiles(files []fs.DirEntry) (uselessFiles []string) { re := regexp.MustCompile("^" + d.filenameBase + ".([0-9]+)-([0-9]+).kv$") var err error - var uselessFiles []string for _, f := range files { if !f.Type().IsRegular() { continue @@ -226,10 +227,7 @@ func (d *Domain) scanStateFiles(files []fs.DirEntry) { } d.files.ReplaceOrInsert(item) } - if len(uselessFiles) > 0 { - log.Info("[snapshots] history can delete", "files", strings.Join(uselessFiles, ",")) - } - + return uselessFiles } func (d *Domain) openFiles() error { diff --git a/state/history.go b/state/history.go index f41ee6c65..a0cec2eca 100644 --- a/state/history.go +++ b/state/history.go @@ -28,7 +28,6 @@ import ( "path/filepath" "regexp" "strconv" - "strings" "sync" "time" @@ -92,17 +91,19 @@ func NewHistory( if err != nil { return nil, err } - h.scanStateFiles(files) + uselessFiles := h.scanStateFiles(files) + for _, f := range uselessFiles { + _ = os.Remove(filepath.Join(h.dir, f)) + } if err = h.openFiles(); err != nil { return nil, fmt.Errorf("NewHistory.openFiles: %s, %w", filenameBase, err) } return &h, nil } -func (h *History) scanStateFiles(files []fs.DirEntry) { +func (h *History) scanStateFiles(files []fs.DirEntry) (uselessFiles []string) { re := regexp.MustCompile("^" + h.filenameBase + ".([0-9]+)-([0-9]+).v$") var err error - var uselessFiles []string for _, f := range files { if !f.Type().IsRegular() { continue @@ -184,9 +185,7 @@ func (h *History) scanStateFiles(files []fs.DirEntry) { } h.files.ReplaceOrInsert(item) } - if len(uselessFiles) > 0 { - log.Info("[snapshots] history can delete", "files", strings.Join(uselessFiles, ",")) - } + return uselessFiles } func (h *History) openFiles() error { diff --git a/state/inverted_index.go b/state/inverted_index.go index 6dc4f3a84..3bcdbe8c3 100644 --- a/state/inverted_index.go +++ b/state/inverted_index.go @@ -28,7 +28,6 @@ import ( "path/filepath" "regexp" "strconv" - "strings" "sync" "time" @@ -87,17 +86,19 @@ func NewInvertedIndex( if err != nil { return nil, fmt.Errorf("NewInvertedIndex: %s, %w", filenameBase, err) } - ii.scanStateFiles(files) + uselessFiles := ii.scanStateFiles(files) + for _, f := range uselessFiles { + _ = os.Remove(filepath.Join(ii.dir, f)) + } if err = ii.openFiles(); err != nil { return nil, fmt.Errorf("NewInvertedIndex: %s, %w", filenameBase, err) } return &ii, nil } -func (ii *InvertedIndex) scanStateFiles(files []fs.DirEntry) { +func (ii *InvertedIndex) scanStateFiles(files []fs.DirEntry) (uselessFiles []string) { re := regexp.MustCompile("^" + ii.filenameBase + ".([0-9]+)-([0-9]+).ef$") var err error - var uselessFiles []string for _, f := range files { if !f.Type().IsRegular() { continue @@ -179,9 +180,7 @@ func (ii *InvertedIndex) scanStateFiles(files []fs.DirEntry) { } ii.files.ReplaceOrInsert(item) } - if len(uselessFiles) > 0 { - log.Info("[snapshots] history can delete", "files", strings.Join(uselessFiles, ",")) - } + return uselessFiles } func (ii *InvertedIndex) missedIdxFiles() (l []*filesItem) {