Skip to content

Commit

Permalink
lens: Add commands to work with Peapod
Browse files Browse the repository at this point in the history
Recently introduced storage component named Peapod is a good candidate
to be inspected by NeoFS Lens app.

Add `peapod` command with `inspect` and `list` sub-commands similar to
`blobovnicza` and `writecache` commands.

Closes #2507.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Aug 16, 2023
1 parent dea0121 commit f402840
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cmd/neofs-lens/internal/peapod/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package peapod

import (
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
blobstorcommon "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
"github.com/spf13/cobra"
)

var inspectCMD = &cobra.Command{
Use: "inspect",
Short: "Object inspection",
Long: `Inspect specific object in a Peapod.`,
Run: inspectFunc,
}

func init() {
common.AddAddressFlag(inspectCMD, &vAddress)
common.AddComponentPathFlag(inspectCMD, &vPath)
common.AddOutputFileFlag(inspectCMD, &vOut)
}

func inspectFunc(cmd *cobra.Command, _ []string) {
var getPrm blobstorcommon.GetPrm

err := getPrm.Address.DecodeString(vAddress)
common.ExitOnErr(cmd, common.Errf("failed to decode object address: %w", err))

ppd := openPeapod(cmd)
defer ppd.Close()

res, err := ppd.Get(getPrm)
common.ExitOnErr(cmd, common.Errf("failed to read object from Peapod: %w", err))

common.PrintObjectHeader(cmd, *res.Object)
common.WriteObjectToFile(cmd, vOut, res.RawData)
}
37 changes: 37 additions & 0 deletions cmd/neofs-lens/internal/peapod/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package peapod

import (
"fmt"
"io"

common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/spf13/cobra"
)

var listCMD = &cobra.Command{
Use: "list",
Short: "Object listing",
Long: `List all objects stored in a Peapod.`,
Run: listFunc,
}

func init() {
common.AddComponentPathFlag(listCMD, &vPath)
}

func listFunc(cmd *cobra.Command, _ []string) {
// other targets can be supported
w := cmd.OutOrStderr()

wAddr := func(addr oid.Address) error {
_, err := io.WriteString(w, fmt.Sprintf("%s\n", addr))
return err
}

ppd := openPeapod(cmd)
defer ppd.Close()

err := ppd.IterateAddresses(wAddr)
common.ExitOnErr(cmd, common.Errf("Peapod iterator failure: %w", err))
}
41 changes: 41 additions & 0 deletions cmd/neofs-lens/internal/peapod/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package peapod

import (
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/compression"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/peapod"
"github.com/spf13/cobra"
)

var (
vAddress string
vPath string
vOut string
)

// Root defines root command for operations with Peapod.
var Root = &cobra.Command{
Use: "peapod",
Short: "Operations with a Peapod",
}

func init() {
Root.AddCommand(listCMD, inspectCMD)
}

// open and returns read-only peapod.Peapod located in vPath.
func openPeapod(cmd *cobra.Command) *peapod.Peapod {
// interval prm doesn't matter for read-only usage, but must be positive
ppd := peapod.New(vPath, 0400, 1)
var compressCfg compression.Config

err := compressCfg.Init()
common.ExitOnErr(cmd, common.Errf("failed to init compression config: %w", err))

ppd.SetCompressor(&compressCfg)

err = ppd.Open(true)
common.ExitOnErr(cmd, common.Errf("failed to open Peapod: %w", err))

return ppd
}
2 changes: 2 additions & 0 deletions cmd/neofs-lens/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/blobovnicza"
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/meta"
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/peapod"
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/writecache"
"github.com/nspcc-dev/neofs-node/misc"
"github.com/nspcc-dev/neofs-node/pkg/util/gendoc"
Expand Down Expand Up @@ -35,6 +36,7 @@ func init() {
command.SetOut(os.Stdout)
command.Flags().Bool("version", false, "Application version")
command.AddCommand(
peapod.Root,
blobovnicza.Root,
meta.Root,
writecache.Root,
Expand Down

0 comments on commit f402840

Please sign in to comment.