[#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)
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

View file

@ -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)

View file

@ -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
}

View file

@ -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)

View file

@ -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(

View file

@ -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(

View file

@ -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
}

View file

@ -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))

View file

@ -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))
}

View file

@ -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
}