Skip to content

Commit

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

Closes #2291.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Oct 16, 2024
1 parent e254f00 commit 1487dee
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 10 deletions.
11 changes: 1 addition & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog for NeoFS Node
attribute, which is used for container domain name in NNS contracts (#2954)
- Save last epoch when metabase was resynchronized (#2966)
- `neofs-lens meta last-resync-epoch` command (#2966)
- `neofs-lens fstree cleanup-tmp` command (#2967)

### Fixed
- Do not search for tombstones when handling their expiration, use local indexes instead (#2929)
Expand All @@ -24,7 +25,6 @@ attribute, which is used for container domain name in NNS contracts (#2954)
- When an error is returned, no additional help output is displayed in cobra-based programs (#2942)
- Use org-wide linter (#2943)
- Timestamps are no longer produced in logs if not running with TTY (#2964)
- Default dial timeout to one minute (#2963)

### Removed
- Support for node.key configuration (#2959)
Expand All @@ -43,15 +43,6 @@ introduced in version 0.22.3 and support for binary keys was removed from
other components in 0.33.0 and 0.37.0. Please migrate to wallets (see 0.37.0
notes) if you've not done it previously.

Increase default timeout for dialing connections in node: `morph.dial_timeout`,
`apiclient.dial_timout`, `apiclient.stream_timeout` and in inner ring:
`morph.dial_timout`, `morph.consensus.p2p.dial_timout`, `mainnet.dial_timout`
to 1 minute. Can be adjusted for fast networks.

Using public keys as a rule target in eACL tables was deprecated and will not
be supported in the next releases, use addresses instead. For more information
call `neofs-cli acl extended create -h`.

## [0.43.0] - 2024-08-20 - Jukdo

### Added
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 unused files in FSTree (forcibly interrupted data writes can leave them)",
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 FSTree storage subsystem",
}

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 opens and returns fstree.FSTree located in vPath.
func openFSTree() (*fstree.FSTree, error) {
fst := fstree.New(
fstree.WithPath(vPath),
fstree.WithPerm(0600),
)

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(false)
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
28 changes: 28 additions & 0 deletions pkg/local_object_storage/blobstor/fstree/fstree.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,31 @@ 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 {
if t.readOnly {
return common.ErrReadOnly

Check warning on line 484 in pkg/local_object_storage/blobstor/fstree/fstree.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/blobstor/fstree/fstree.go#L482-L484

Added lines #L482 - L484 were not covered by tests
}

err := filepath.WalkDir(t.RootPath,
func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err

Check warning on line 490 in pkg/local_object_storage/blobstor/fstree/fstree.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/blobstor/fstree/fstree.go#L487-L490

Added lines #L487 - L490 were not covered by tests
}
if !d.IsDir() && strings.Contains(d.Name(), "#") {
err = os.RemoveAll(path)
if err != nil {
return err

Check warning on line 495 in pkg/local_object_storage/blobstor/fstree/fstree.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/blobstor/fstree/fstree.go#L492-L495

Added lines #L492 - L495 were not covered by tests
}
}

return nil

Check warning on line 499 in pkg/local_object_storage/blobstor/fstree/fstree.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/blobstor/fstree/fstree.go#L499

Added line #L499 was not covered by tests
},
)
if err != nil {
return fmt.Errorf("could not walk through %q directory: %w", t.RootPath, err)

Check warning on line 503 in pkg/local_object_storage/blobstor/fstree/fstree.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/blobstor/fstree/fstree.go#L502-L503

Added lines #L502 - L503 were not covered by tests
}

return nil

Check warning on line 506 in pkg/local_object_storage/blobstor/fstree/fstree.go

View check run for this annotation

Codecov / codecov/patch

pkg/local_object_storage/blobstor/fstree/fstree.go#L506

Added line #L506 was not covered by tests
}

0 comments on commit 1487dee

Please sign in to comment.