Skip to content

Commit

Permalink
fstree: clean up temporary files
Browse files Browse the repository at this point in the history
Add method to remove temporary files from `genericWriter.writeData` and call it
in `FSTree.Init`.

Closes #2291.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Oct 9, 2024
1 parent 530db9a commit 8f8345b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog for NeoFS Node
- `node` config option `storage.ignore_uninited_shards` (#2953)
- For `neofs-cli container create`, add `--global-name` flag, that sets name attribute as the value of `__NEOFS__NAME`
attribute, which is used for container domain name in NNS contracts (#2954)
- Clean up temporary files in FSTree on start (#2967)

### Fixed
- Do not search for tombstones when handling their expiration, use local indexes instead (#2929)
Expand Down
5 changes: 5 additions & 0 deletions pkg/local_object_storage/blobstor/fstree/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func (t *FSTree) Init() error {
t.writer = w
}
}

err = t.CleanUpTmp()
if err != nil {
return fmt.Errorf("clean up tmp: %w", err)
}
return nil
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/local_object_storage/blobstor/fstree/fstree.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math"
"os"
"path/filepath"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -477,3 +478,23 @@ func (t *FSTree) SetCompressor(cc *compression.Config) {
func (t *FSTree) SetReportErrorFunc(_ func(string, error)) {
// Do nothing, FSTree can encounter only one error which is returned.
}

// CleanUpTmp removes all temporary files garbage
func (t *FSTree) CleanUpTmp() error {
re := regexp.MustCompile(`.*#[0-9]+$`)

err := filepath.WalkDir(t.RootPath,
func(path string, d fs.DirEntry, _ error) error {
if !d.IsDir() && re.MatchString(d.Name()) {
_ = os.RemoveAll(path)
}

return nil
},
)
if err != nil {
return fmt.Errorf("could not walk through %q directory: %w", t.RootPath, err)
}

return nil
}

0 comments on commit 8f8345b

Please sign in to comment.