Skip to content

Commit

Permalink
neofs-lens: add indexes inspection command
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Jul 2, 2024
1 parent ee252df commit 490e3db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog for NeoFS Node
## [Unreleased]

### Added
- Indexes inspection command to neofs-lens (#2882)

### Fixed
- Control service's Drop call does not clean metabase (#2822)
Expand Down
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 @@ -35,6 +35,7 @@ func init() {
listGarbageCMD,
writeObjectCMD,
getCMD,
statCMD,
)
}

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

import (
"fmt"

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 statCMD = &cobra.Command{
Use: "stat",
Short: "Object status information",
Long: `Get metabase's indexes related to an object.`,
Args: cobra.NoArgs,
Run: statFunc,
}

func init() {
common.AddAddressFlag(statCMD, &vAddress)
common.AddComponentPathFlag(statCMD, &vPath)
}

func statFunc(cmd *cobra.Command, _ []string) {
var addr oid.Address

err := addr.DecodeString(vAddress)
common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err))

db := openMeta(cmd, true)
defer db.Close()

res, err := db.ObjectStatus(addr)
common.ExitOnErr(cmd, common.Errf("reading object status: %w", err))

cmd.Printf("Object state: %s\n", res.State)
cmd.Printf("Starage's ID: %s\n", res.StorageID)
cmd.Println("Indexes:")
for _, bucket := range res.Buckets {
valStr := "<empty>"
if bucket.Value != nil {
valStr = fmt.Sprintf("%x", bucket.Value)
}

cmd.Printf("\tBucket: %d\n"+
"\tValue (HEX): %s\n", bucket.BucketIndex, valStr)
}
}

0 comments on commit 490e3db

Please sign in to comment.