2022-08-23 14:05:32 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
common "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2022-08-23 14:05:32 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var inspectCMD = &cobra.Command{
|
|
|
|
Use: "inspect",
|
|
|
|
Short: "Object inspection",
|
|
|
|
Long: `Inspect specific object in a metabase.`,
|
|
|
|
Run: inspectFunc,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
common.AddAddressFlag(inspectCMD, &vAddress)
|
|
|
|
common.AddComponentPathFlag(inspectCMD, &vPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
func inspectFunc(cmd *cobra.Command, _ []string) {
|
|
|
|
var addr oid.Address
|
|
|
|
|
|
|
|
err := addr.DecodeString(vAddress)
|
|
|
|
common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err))
|
|
|
|
|
2022-08-24 12:09:52 +00:00
|
|
|
db := openMeta(cmd)
|
|
|
|
defer db.Close()
|
2022-08-23 14:05:32 +00:00
|
|
|
|
|
|
|
storageID := meta.StorageIDPrm{}
|
|
|
|
storageID.SetAddress(addr)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
resStorageID, err := db.StorageID(cmd.Context(), storageID)
|
2022-08-23 14:05:32 +00:00
|
|
|
common.ExitOnErr(cmd, common.Errf("could not check if the obj is small: %w", err))
|
|
|
|
|
|
|
|
if id := resStorageID.StorageID(); id != nil {
|
|
|
|
cmd.Printf("Object storageID: %s\n\n", blobovnicza.NewIDFromBytes(id).String())
|
|
|
|
} else {
|
|
|
|
cmd.Printf("Object does not contain storageID\n\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
prm := meta.GetPrm{}
|
|
|
|
prm.SetAddress(addr)
|
|
|
|
prm.SetRaw(true)
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
siErr := new(objectSDK.SplitInfoError)
|
2022-08-23 14:05:32 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := db.Get(cmd.Context(), prm)
|
2022-08-23 14:05:32 +00:00
|
|
|
if errors.As(err, &siErr) {
|
|
|
|
link, linkSet := siErr.SplitInfo().Link()
|
|
|
|
last, lastSet := siErr.SplitInfo().LastPart()
|
|
|
|
|
|
|
|
fmt.Println("Object is split")
|
|
|
|
cmd.Println("\tSplitID:", siErr.SplitInfo().SplitID().String())
|
|
|
|
|
|
|
|
if linkSet {
|
|
|
|
cmd.Println("\tLink:", link)
|
|
|
|
}
|
|
|
|
if lastSet {
|
|
|
|
cmd.Println("\tLast:", last)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
common.ExitOnErr(cmd, common.Errf("could not get object: %w", err))
|
|
|
|
|
|
|
|
common.PrintObjectHeader(cmd, *res.Header())
|
|
|
|
}
|