-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
neofs-lens: add indexes inspection command
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ func init() { | |
listGarbageCMD, | ||
writeObjectCMD, | ||
getCMD, | ||
statCMD, | ||
) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |