diff --git a/cmd/neofs-lens/internal/blobovnicza/inspect.go b/cmd/neofs-lens/internal/blobovnicza/inspect.go index db9601cc38..5799585072 100644 --- a/cmd/neofs-lens/internal/blobovnicza/inspect.go +++ b/cmd/neofs-lens/internal/blobovnicza/inspect.go @@ -27,12 +27,7 @@ func inspectFunc(cmd *cobra.Command, _ []string) { err := addr.DecodeString(vAddress) common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err)) - blz := blobovnicza.New( - blobovnicza.WithPath(vPath), - blobovnicza.WithReadOnly(true), - ) - common.ExitOnErr(cmd, blz.Open()) - + blz := openBlobovnicza(cmd) defer blz.Close() var prm blobovnicza.GetPrm diff --git a/cmd/neofs-lens/internal/blobovnicza/list.go b/cmd/neofs-lens/internal/blobovnicza/list.go index 54b3c785ea..2d116efe40 100644 --- a/cmd/neofs-lens/internal/blobovnicza/list.go +++ b/cmd/neofs-lens/internal/blobovnicza/list.go @@ -30,13 +30,7 @@ func listFunc(cmd *cobra.Command, _ []string) { return err } - blz := blobovnicza.New( - blobovnicza.WithPath(vPath), - blobovnicza.WithReadOnly(true), - ) - - common.ExitOnErr(cmd, blz.Open()) - + blz := openBlobovnicza(cmd) defer blz.Close() err := blobovnicza.IterateAddresses(blz, wAddr) diff --git a/cmd/neofs-lens/internal/blobovnicza/root.go b/cmd/neofs-lens/internal/blobovnicza/root.go index aa82c25163..59ce6e9907 100644 --- a/cmd/neofs-lens/internal/blobovnicza/root.go +++ b/cmd/neofs-lens/internal/blobovnicza/root.go @@ -1,6 +1,10 @@ package blobovnicza -import "github.com/spf13/cobra" +import ( + common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" + "github.com/spf13/cobra" +) var ( vAddress string @@ -17,3 +21,13 @@ var Root = &cobra.Command{ func init() { Root.AddCommand(listCMD, inspectCMD) } + +func openBlobovnicza(cmd *cobra.Command) *blobovnicza.Blobovnicza { + blz := blobovnicza.New( + blobovnicza.WithPath(vPath), + blobovnicza.WithReadOnly(true), + ) + common.ExitOnErr(cmd, blz.Open()) + + return blz +} diff --git a/cmd/neofs-lens/internal/meta/inspect.go b/cmd/neofs-lens/internal/meta/inspect.go index 3a05e2fa56..7d84a1bd7d 100644 --- a/cmd/neofs-lens/internal/meta/inspect.go +++ b/cmd/neofs-lens/internal/meta/inspect.go @@ -3,7 +3,6 @@ package meta import ( "errors" "fmt" - "time" common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" @@ -11,7 +10,6 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/spf13/cobra" - "go.etcd.io/bbolt" ) var inspectCMD = &cobra.Command{ @@ -32,16 +30,8 @@ func inspectFunc(cmd *cobra.Command, _ []string) { err := addr.DecodeString(vAddress) common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err)) - db := meta.New( - meta.WithPath(vPath), - meta.WithBoltDBOptions(&bbolt.Options{ - ReadOnly: true, - Timeout: 100 * time.Millisecond, - }), - meta.WithEpochState(epochState{}), - ) - - common.ExitOnErr(cmd, common.Errf("could not open metabase: %w", db.Open(true))) + db := openMeta(cmd) + defer db.Close() storageID := meta.StorageIDPrm{} storageID.SetAddress(addr) diff --git a/cmd/neofs-lens/internal/meta/list-garbage.go b/cmd/neofs-lens/internal/meta/list-garbage.go index 4ca7499877..d5f70c9503 100644 --- a/cmd/neofs-lens/internal/meta/list-garbage.go +++ b/cmd/neofs-lens/internal/meta/list-garbage.go @@ -1,12 +1,9 @@ package meta import ( - "time" - common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/spf13/cobra" - "go.etcd.io/bbolt" ) var listGarbageCMD = &cobra.Command{ @@ -21,16 +18,8 @@ func init() { } func listGarbageFunc(cmd *cobra.Command, _ []string) { - db := meta.New( - meta.WithPath(vPath), - meta.WithBoltDBOptions(&bbolt.Options{ - ReadOnly: true, - Timeout: 100 * time.Millisecond, - }), - meta.WithEpochState(epochState{}), - ) - - common.ExitOnErr(cmd, common.Errf("could not open metabase: %w", db.Open(true))) + db := openMeta(cmd) + defer db.Close() var garbPrm meta.GarbageIterationPrm garbPrm.SetHandler( diff --git a/cmd/neofs-lens/internal/meta/list-graveyard.go b/cmd/neofs-lens/internal/meta/list-graveyard.go index 0853452e16..d5bcfe5d60 100644 --- a/cmd/neofs-lens/internal/meta/list-graveyard.go +++ b/cmd/neofs-lens/internal/meta/list-graveyard.go @@ -1,12 +1,9 @@ package meta import ( - "time" - common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/spf13/cobra" - "go.etcd.io/bbolt" ) var listGraveyardCMD = &cobra.Command{ @@ -21,16 +18,8 @@ func init() { } func listGraveyardFunc(cmd *cobra.Command, _ []string) { - db := meta.New( - meta.WithPath(vPath), - meta.WithBoltDBOptions(&bbolt.Options{ - ReadOnly: true, - Timeout: 100 * time.Millisecond, - }), - meta.WithEpochState(epochState{}), - ) - - common.ExitOnErr(cmd, common.Errf("could not open metabase: %w", db.Open(true))) + db := openMeta(cmd) + defer db.Close() var gravePrm meta.GraveyardIterationPrm gravePrm.SetHandler( diff --git a/cmd/neofs-lens/internal/meta/root.go b/cmd/neofs-lens/internal/meta/root.go index 9534abdb7a..fca99512b5 100644 --- a/cmd/neofs-lens/internal/meta/root.go +++ b/cmd/neofs-lens/internal/meta/root.go @@ -1,7 +1,12 @@ package meta import ( + "time" + + common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" + meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/spf13/cobra" + "go.etcd.io/bbolt" ) var ( @@ -28,3 +33,17 @@ func init() { listGarbageCMD, ) } + +func openMeta(cmd *cobra.Command) *meta.DB { + db := meta.New( + meta.WithPath(vPath), + meta.WithBoltDBOptions(&bbolt.Options{ + ReadOnly: true, + Timeout: 100 * time.Millisecond, + }), + meta.WithEpochState(epochState{}), + ) + common.ExitOnErr(cmd, common.Errf("could not open metabase: %w", db.Open(true))) + + return db +} diff --git a/cmd/neofs-lens/internal/writecache/inspect.go b/cmd/neofs-lens/internal/writecache/inspect.go index 1f5ef7ffaa..f1dcfd9aec 100644 --- a/cmd/neofs-lens/internal/writecache/inspect.go +++ b/cmd/neofs-lens/internal/writecache/inspect.go @@ -21,9 +21,7 @@ func init() { } func inspectFunc(cmd *cobra.Command, _ []string) { - db, err := writecache.OpenDB(vPath, true) - common.ExitOnErr(cmd, common.Errf("could not open write-cache db: %w", err)) - + db := openWC(cmd) defer db.Close() data, err := writecache.Get(db, []byte(vAddress)) diff --git a/cmd/neofs-lens/internal/writecache/list.go b/cmd/neofs-lens/internal/writecache/list.go index 2da1c0836f..e2d7e3d34f 100644 --- a/cmd/neofs-lens/internal/writecache/list.go +++ b/cmd/neofs-lens/internal/writecache/list.go @@ -30,11 +30,9 @@ func listFunc(cmd *cobra.Command, _ []string) { return err } - db, err := writecache.OpenDB(vPath, true) - common.ExitOnErr(cmd, common.Errf("could not open write-cache db: %w", err)) - + db := openWC(cmd) defer db.Close() - err = writecache.IterateDB(db, wAddr) + err := writecache.IterateDB(db, wAddr) common.ExitOnErr(cmd, common.Errf("write-cache iterator failure: %w", err)) } diff --git a/cmd/neofs-lens/internal/writecache/root.go b/cmd/neofs-lens/internal/writecache/root.go index 493a787e46..0e0e778672 100644 --- a/cmd/neofs-lens/internal/writecache/root.go +++ b/cmd/neofs-lens/internal/writecache/root.go @@ -1,6 +1,11 @@ package writecache -import "github.com/spf13/cobra" +import ( + common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" + "github.com/spf13/cobra" + "go.etcd.io/bbolt" +) var ( vAddress string @@ -17,3 +22,10 @@ var Root = &cobra.Command{ func init() { Root.AddCommand(listCMD, inspectCMD) } + +func openWC(cmd *cobra.Command) *bbolt.DB { + db, err := writecache.OpenDB(vPath, true) + common.ExitOnErr(cmd, common.Errf("could not open write-cache db: %w", err)) + + return db +}