[#1714] lens: Add open*COMPONENT* funcs

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-08-24 15:09:52 +03:00 committed by LeL
parent 01d7c007aa
commit fa18100489
10 changed files with 58 additions and 60 deletions

View file

@ -27,12 +27,7 @@ func inspectFunc(cmd *cobra.Command, _ []string) {
err := addr.DecodeString(vAddress) err := addr.DecodeString(vAddress)
common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err)) common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err))
blz := blobovnicza.New( blz := openBlobovnicza(cmd)
blobovnicza.WithPath(vPath),
blobovnicza.WithReadOnly(true),
)
common.ExitOnErr(cmd, blz.Open())
defer blz.Close() defer blz.Close()
var prm blobovnicza.GetPrm var prm blobovnicza.GetPrm

View file

@ -30,13 +30,7 @@ func listFunc(cmd *cobra.Command, _ []string) {
return err return err
} }
blz := blobovnicza.New( blz := openBlobovnicza(cmd)
blobovnicza.WithPath(vPath),
blobovnicza.WithReadOnly(true),
)
common.ExitOnErr(cmd, blz.Open())
defer blz.Close() defer blz.Close()
err := blobovnicza.IterateAddresses(blz, wAddr) err := blobovnicza.IterateAddresses(blz, wAddr)

View file

@ -1,6 +1,10 @@
package blobovnicza 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 ( var (
vAddress string vAddress string
@ -17,3 +21,13 @@ var Root = &cobra.Command{
func init() { func init() {
Root.AddCommand(listCMD, inspectCMD) 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
}

View file

@ -3,7 +3,6 @@ package meta
import ( import (
"errors" "errors"
"fmt" "fmt"
"time"
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
@ -11,7 +10,6 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.etcd.io/bbolt"
) )
var inspectCMD = &cobra.Command{ var inspectCMD = &cobra.Command{
@ -32,16 +30,8 @@ func inspectFunc(cmd *cobra.Command, _ []string) {
err := addr.DecodeString(vAddress) err := addr.DecodeString(vAddress)
common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err)) common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err))
db := meta.New( db := openMeta(cmd)
meta.WithPath(vPath), defer db.Close()
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)))
storageID := meta.StorageIDPrm{} storageID := meta.StorageIDPrm{}
storageID.SetAddress(addr) storageID.SetAddress(addr)

View file

@ -1,12 +1,9 @@
package meta package meta
import ( import (
"time"
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.etcd.io/bbolt"
) )
var listGarbageCMD = &cobra.Command{ var listGarbageCMD = &cobra.Command{
@ -21,16 +18,8 @@ func init() {
} }
func listGarbageFunc(cmd *cobra.Command, _ []string) { func listGarbageFunc(cmd *cobra.Command, _ []string) {
db := meta.New( db := openMeta(cmd)
meta.WithPath(vPath), defer db.Close()
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)))
var garbPrm meta.GarbageIterationPrm var garbPrm meta.GarbageIterationPrm
garbPrm.SetHandler( garbPrm.SetHandler(

View file

@ -1,12 +1,9 @@
package meta package meta
import ( import (
"time"
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.etcd.io/bbolt"
) )
var listGraveyardCMD = &cobra.Command{ var listGraveyardCMD = &cobra.Command{
@ -21,16 +18,8 @@ func init() {
} }
func listGraveyardFunc(cmd *cobra.Command, _ []string) { func listGraveyardFunc(cmd *cobra.Command, _ []string) {
db := meta.New( db := openMeta(cmd)
meta.WithPath(vPath), defer db.Close()
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)))
var gravePrm meta.GraveyardIterationPrm var gravePrm meta.GraveyardIterationPrm
gravePrm.SetHandler( gravePrm.SetHandler(

View file

@ -1,7 +1,12 @@
package meta package meta
import ( 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" "github.com/spf13/cobra"
"go.etcd.io/bbolt"
) )
var ( var (
@ -28,3 +33,17 @@ func init() {
listGarbageCMD, 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
}

View file

@ -21,9 +21,7 @@ func init() {
} }
func inspectFunc(cmd *cobra.Command, _ []string) { func inspectFunc(cmd *cobra.Command, _ []string) {
db, err := writecache.OpenDB(vPath, true) db := openWC(cmd)
common.ExitOnErr(cmd, common.Errf("could not open write-cache db: %w", err))
defer db.Close() defer db.Close()
data, err := writecache.Get(db, []byte(vAddress)) data, err := writecache.Get(db, []byte(vAddress))

View file

@ -30,11 +30,9 @@ func listFunc(cmd *cobra.Command, _ []string) {
return err return err
} }
db, err := writecache.OpenDB(vPath, true) db := openWC(cmd)
common.ExitOnErr(cmd, common.Errf("could not open write-cache db: %w", err))
defer db.Close() defer db.Close()
err = writecache.IterateDB(db, wAddr) err := writecache.IterateDB(db, wAddr)
common.ExitOnErr(cmd, common.Errf("write-cache iterator failure: %w", err)) common.ExitOnErr(cmd, common.Errf("write-cache iterator failure: %w", err))
} }

View file

@ -1,6 +1,11 @@
package writecache 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 ( var (
vAddress string vAddress string
@ -17,3 +22,10 @@ var Root = &cobra.Command{
func init() { func init() {
Root.AddCommand(listCMD, inspectCMD) 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
}