-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fstree : clean up temporary files (#2967)
- Loading branch information
Showing
5 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
func cleanupFunc(cmd *cobra.Command, _ []string) error { | ||
fst, err := openFSTree() | ||
if err != nil { | ||
return err | ||
} | ||
defer fst.Close() | ||
|
||
cmd.Println("Cleaning up tmp files in FSTree") | ||
|
||
return fst.CleanUpTmp() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
// openFSTree opens and returns fstree.FSTree located in vPath. | ||
func openFSTree() (*fstree.FSTree, error) { | ||
fst := fstree.New( | ||
fstree.WithPath(vPath), | ||
fstree.WithPerm(0600), | ||
) | ||
|
||
var compressCfg compression.Config | ||
|
||
err := compressCfg.Init() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to init compression config: %w", err) | ||
} | ||
|
||
fst.SetCompressor(&compressCfg) | ||
|
||
err = fst.Open(false) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to open FSTree: %w", err) | ||
} | ||
|
||
return fst, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters