Skip to content

Commit

Permalink
Feat/new meta base helpers in neofs lens (#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov committed Apr 25, 2024
2 parents 121c222 + b60c11e commit b5e22e1
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog for NeoFS Node

### Added
- Container estimations inspector to neofs-adm (#2826)
- Metabase object lister to neofs-lens (#2834)
- Shard ID from metabase reader to neofs-lens (#2834)

### Fixed
- Attribute ACL checks for the first split object (#2820)
Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/meta/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var getCMD = &cobra.Command{
Use: "get",
Short: "Object inspection",
Long: `Get specific object from a metabase.`,
Args: cobra.NoArgs,
Run: getFunc,
}

Expand Down
28 changes: 28 additions & 0 deletions cmd/neofs-lens/internal/meta/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package meta

import (
"github.com/mr-tron/base58"
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
"github.com/spf13/cobra"
)

var idCMD = &cobra.Command{
Use: "id",
Short: "Read shard ID the metabase is attached to",
Args: cobra.NoArgs,
Run: idFunc,
}

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

func idFunc(cmd *cobra.Command, _ []string) {
db := openMeta(cmd, true)
defer db.Close()

idRaw, err := db.ReadShardID()
common.ExitOnErr(cmd, common.Errf("metabase's `ReadShardID`: %w", err))

cmd.Println(base58.Encode(idRaw))
}
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/meta/list-garbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var listGarbageCMD = &cobra.Command{
Use: "list-garbage",
Short: "Garbage listing",
Long: `List all the objects that have received GC Mark.`,
Args: cobra.NoArgs,
Run: listGarbageFunc,
}

Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/meta/list-graveyard.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var listGraveyardCMD = &cobra.Command{
Use: "list-graveyard",
Short: "Graveyard listing",
Long: `List all the objects that have been covered with a Tomb Stone.`,
Args: cobra.NoArgs,
Run: listGraveyardFunc,
}

Expand Down
49 changes: 49 additions & 0 deletions cmd/neofs-lens/internal/meta/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package meta

import (
"fmt"

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

var listCMD = &cobra.Command{
Use: "list",
Short: "List objects in metabase (metabase's List method)",
Args: cobra.NoArgs,
Run: listFunc,
}

var vLimit uint32

const limitFlagName = "limit"

func init() {
listCMD.Flags().Uint32Var(&vLimit, limitFlagName, 0, "Number of objects to list")
err := listCMD.MarkFlagRequired(limitFlagName)
if err != nil {
panic(fmt.Errorf("mark required flag %s failed: %w", limitFlagName, err))
}

common.AddComponentPathFlag(listCMD, &vPath)
}

func listFunc(cmd *cobra.Command, _ []string) {
db := openMeta(cmd, true)
defer db.Close()

if vLimit == 0 {
common.ExitOnErr(cmd, fmt.Errorf("%s flag must be positive", limitFlagName))
}

var prm meta.ListPrm
prm.SetCount(vLimit)

res, err := db.ListWithCursor(prm)
common.ExitOnErr(cmd, common.Errf("metabase's `ListWithCursor`: %w", err))

for _, addressWithType := range res.AddressList() {
cmd.Printf("%s, Type: %s\n", addressWithType.Address, addressWithType.Type)
}
}
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/meta/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var Root = &cobra.Command{

func init() {
Root.AddCommand(
listCMD,
listGraveyardCMD,
listGarbageCMD,
writeObjectCMD,
Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/object/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
var linkCMD = &cobra.Command{
Use: "link",
Short: "Inspect link object",
Args: cobra.NoArgs,
Run: linkFunc,
}

Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/peapod/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var getCMD = &cobra.Command{
Use: "get",
Short: "Get object",
Long: `Get specific object from a Peapod.`,
Args: cobra.NoArgs,
Run: getFunc,
}

Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/peapod/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var listCMD = &cobra.Command{
Use: "list",
Short: "Object listing",
Long: `List all objects stored in a Peapod.`,
Args: cobra.NoArgs,
Run: listFunc,
}

Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/writecache/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var getCMD = &cobra.Command{
Use: "get",
Short: "Object inspection",
Long: `Get specific object from a write-cache.`,
Args: cobra.NoArgs,
Run: getFunc,
}

Expand Down
1 change: 1 addition & 0 deletions cmd/neofs-lens/internal/writecache/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var listCMD = &cobra.Command{
Use: "list",
Short: "Object listing",
Long: `List all objects stored in a write-cache.`,
Args: cobra.NoArgs,
Run: listFunc,
}

Expand Down

0 comments on commit b5e22e1

Please sign in to comment.