Skip to content

Commit

Permalink
neofs-lens: add fstree cleanup-tmp command
Browse files Browse the repository at this point in the history
Add command to cleaning up temporary files in FSTree by path.

Ref #2291.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Oct 9, 2024
1 parent f9930c4 commit f156fb4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Changelog for NeoFS Node
- 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)
- `neofs-lens fstree cleanup-tmp` command (#2967)

### Fixed
- Do not search for tombstones when handling their expiration, use local indexes instead (#2929)
Expand Down
30 changes: 30 additions & 0 deletions cmd/neofs-lens/internal/fstree/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fstree

import (
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
"github.com/spf13/cobra"
)

var cleanupCMD = &cobra.Command{
Use: "cleanup-tmp",
Short: "Clean up tmp files in FSTree",
Long: "Clean up temporary files in FSTree",
Args: cobra.NoArgs,
RunE: cleanupFunc,
}

func init() {
common.AddComponentPathFlag(cleanupCMD, &vPath)

Check warning on line 17 in cmd/neofs-lens/internal/fstree/cleanup.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/cleanup.go#L16-L17

Added lines #L16 - L17 were not covered by tests
}

func cleanupFunc(cmd *cobra.Command, _ []string) error {
fst, err := openFSTree()
if err != nil {
return err

Check warning on line 23 in cmd/neofs-lens/internal/fstree/cleanup.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/cleanup.go#L20-L23

Added lines #L20 - L23 were not covered by tests
}
defer fst.Close()

Check warning on line 25 in cmd/neofs-lens/internal/fstree/cleanup.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/cleanup.go#L25

Added line #L25 was not covered by tests

cmd.Println("Cleaning up tmp files in FSTree")

Check warning on line 27 in cmd/neofs-lens/internal/fstree/cleanup.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/cleanup.go#L27

Added line #L27 was not covered by tests

return fst.CleanUpTmp()

Check warning on line 29 in cmd/neofs-lens/internal/fstree/cleanup.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/cleanup.go#L29

Added line #L29 was not covered by tests
}
47 changes: 47 additions & 0 deletions cmd/neofs-lens/internal/fstree/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fstree

import (
"fmt"

"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
"github.com/spf13/cobra"
)

var (
vPath string
)

// Root defines root command for operations with FSTree.
var Root = &cobra.Command{
Use: "fstree",
Short: "Operations with a FSTree",
}

func init() {
Root.AddCommand(cleanupCMD)

Check warning on line 22 in cmd/neofs-lens/internal/fstree/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/root.go#L21-L22

Added lines #L21 - L22 were not covered by tests
}

// openFSTree open and returns read-only fstree.FSTree located in vPath.
func openFSTree() (*fstree.FSTree, error) {
fst := fstree.New(
fstree.WithPath(vPath),
fstree.WithPerm(0400),
)

Check warning on line 30 in cmd/neofs-lens/internal/fstree/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/root.go#L26-L30

Added lines #L26 - L30 were not covered by tests

var compressCfg compression.Config

Check warning on line 32 in cmd/neofs-lens/internal/fstree/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/root.go#L32

Added line #L32 was not covered by tests

err := compressCfg.Init()
if err != nil {
return nil, fmt.Errorf("failed to init compression config: %w", err)

Check warning on line 36 in cmd/neofs-lens/internal/fstree/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/root.go#L34-L36

Added lines #L34 - L36 were not covered by tests
}

fst.SetCompressor(&compressCfg)

Check warning on line 39 in cmd/neofs-lens/internal/fstree/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/root.go#L39

Added line #L39 was not covered by tests

err = fst.Open(true)
if err != nil {
return nil, fmt.Errorf("failed to open FSTree: %w", err)

Check warning on line 43 in cmd/neofs-lens/internal/fstree/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/root.go#L41-L43

Added lines #L41 - L43 were not covered by tests
}

return fst, nil

Check warning on line 46 in cmd/neofs-lens/internal/fstree/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/internal/fstree/root.go#L46

Added line #L46 was not covered by tests
}
2 changes: 2 additions & 0 deletions cmd/neofs-lens/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/nspcc-dev/neofs-node/cmd/internal/cmderr"
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/fstree"
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/meta"
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/object"
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/peapod"
Expand Down Expand Up @@ -44,6 +45,7 @@ func init() {
writecache.Root,
storage.Root,
object.Root,
fstree.Root,

Check warning on line 48 in cmd/neofs-lens/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-lens/root.go#L48

Added line #L48 was not covered by tests
gendoc.Command(command),
)
}
Expand Down

0 comments on commit f156fb4

Please sign in to comment.