feat(cli): hybrid cloud support query vol hybrid storage info

close: #22304812 #22304800
Signed-off-by: NaturalSelect <huangzhibin1@oppo.com>
This commit is contained in:
NaturalSelect 2024-06-24 14:53:54 +08:00 committed by AmazingChi
parent 014396bdf9
commit f029d45f6a
3 changed files with 49 additions and 9 deletions

View File

@ -17,6 +17,7 @@ package cmd
import (
"fmt"
"math"
"sort"
"strconv"
"strings"
"time"
@ -548,6 +549,17 @@ func formatMetaPartitionInfo(partition *proto.MetaPartitionInfo) string {
for partitionHost, id := range partition.MissNodes {
sb.WriteString(fmt.Sprintf(" [%v, %v]\n", partitionHost, id))
}
if len(partition.StatByStorageClass) != 0 {
sb.WriteString("\n")
sort.Slice(partition.StatByStorageClass, func(i, j int) bool {
return partition.StatByStorageClass[i].StorageClass < partition.StatByStorageClass[j].StorageClass
})
sb.WriteString("Usage by storageClass:\n")
sb.WriteString(fmt.Sprintf("%v\n", hybridCloudStorageTableHeader))
for _, view := range partition.StatByStorageClass {
sb.WriteString(fmt.Sprintf("%v\n", formatHybridCloudStorageTableRow(view)))
}
}
return sb.String()
}
@ -1070,3 +1082,13 @@ func replicaInHost(hosts []string, replica string) bool {
func formatDecommissionTokenStatus(status *proto.DecommissionTokenStatus) string {
return fmt.Sprintf("Nodeset %v: %v/%v", status.NodesetID, status.CurTokenNum, status.MaxTokenNum)
}
var (
hybridCloudStorageTablePattern = "%-12v %-12v %-12v"
hybridCloudStorageTableHeader = fmt.Sprintf(hybridCloudStorageTablePattern, "STORAGE CLASS", "INODE COUNT", "SIZE")
)
func formatHybridCloudStorageTableRow(view *proto.StatOftorageClass) (row string) {
row = fmt.Sprintf(hybridCloudStorageTablePattern, proto.StorageClassString(view.StorageClass), view.InodeCount, view.UsedSizeBytes)
return
}

View File

@ -72,7 +72,7 @@ func newMetaPartitionGetCmd(client *master.MasterClient) *cobra.Command {
if partition, err = client.ClientAPI().GetMetaPartition(partitionID); err != nil {
return
}
stdout(formatMetaPartitionInfo(partition))
stdout("%v\n", formatMetaPartitionInfo(partition))
},
}
return cmd
@ -83,10 +83,10 @@ func newListCorruptMetaPartitionCmd(client *master.MasterClient) *cobra.Command
Use: CliOpCheck,
Short: cmdCheckCorruptMetaPartitionShort,
Long: `If the meta nodes are marked as "Inactive", it means the nodes has been not available for a long time. It is suggested to eliminate
the network, disk or other problems first. If the bad nodes can never be "active" again, they are called corrupt nodes. And the
"decommission" command can be used to discard the corrupt nodes. However, if more than half replicas of a partition are on
the corrupt nodes, the few remaining replicas can not reach an agreement with one leader. In this case, you can use the
"metapartition reset" command to fix the problem, however this action may lead to data loss, be careful to do this. The
the network, disk or other problems first. If the bad nodes can never be "active" again, they are called corrupt nodes. And the
"decommission" command can be used to discard the corrupt nodes. However, if more than half replicas of a partition are on
the corrupt nodes, the few remaining replicas can not reach an agreement with one leader. In this case, you can use the
"metapartition reset" command to fix the problem, however this action may lead to data loss, be careful to do this. The
"reset" command will be released in next version.`,
Run: func(cmd *cobra.Command, args []string) {
var (

View File

@ -664,10 +664,10 @@ func newVolUpdateCmd(client *master.MasterClient) *cobra.Command {
confirmString.WriteString(fmt.Sprintf(" EnableAutoDpMetaRepair : %v -> %v\n", vv.EnableAutoDpMetaRepair, enable))
vv.EnableAutoDpMetaRepair = enable
} else {
confirmString.WriteString(fmt.Sprintf(" EnableAutoDpMetaRepair : %v", vv.EnableAutoDpMetaRepair))
confirmString.WriteString(fmt.Sprintf(" EnableAutoDpMetaRepair : %v\n", vv.EnableAutoDpMetaRepair))
}
} else {
confirmString.WriteString(fmt.Sprintf(" EnableAutoDpMetaRepair : %v", vv.EnableAutoDpMetaRepair))
confirmString.WriteString(fmt.Sprintf(" EnableAutoDpMetaRepair : %v\n", vv.EnableAutoDpMetaRepair))
}
if optVolStorageClass != 0 {
@ -760,8 +760,9 @@ const (
func newVolInfoCmd(client *master.MasterClient) *cobra.Command {
var (
optMetaDetail bool
optDataDetail bool
optMetaDetail bool
optDataDetail bool
opHybridCloudDetail bool
)
cmd := &cobra.Command{
@ -782,6 +783,22 @@ func newVolInfoCmd(client *master.MasterClient) *cobra.Command {
// print summary info
stdout("Summary:\n%s\n", formatSimpleVolView(svv))
if opHybridCloudDetail {
var info *proto.VolStatInfo
if info, err = client.ClientAPI().GetVolumeStat(volumeName); err != nil {
err = fmt.Errorf("Get volume hyrbid cloud detail information failed:\n%v\n", err)
return
}
stdout("Usage by storage class:\n")
stdout("%v\n", hybridCloudStorageTableHeader)
sort.Slice(info.StatByStorageClass, func(i, j int) bool {
return info.StatByStorageClass[i].StorageClass < info.StatByStorageClass[j].StorageClass
})
for _, view := range info.StatByStorageClass {
stdout("%v\n", formatHybridCloudStorageTableRow(view))
}
}
// print metadata detail
if optMetaDetail {
var views []*proto.MetaPartitionView
@ -825,6 +842,7 @@ func newVolInfoCmd(client *master.MasterClient) *cobra.Command {
}
cmd.Flags().BoolVarP(&optMetaDetail, "meta-partition", "m", false, "Display meta partition detail information")
cmd.Flags().BoolVarP(&optDataDetail, "data-partition", "d", false, "Display data partition detail information")
cmd.Flags().BoolVarP(&opHybridCloudDetail, "storage-class", "s", false, "Display hybrid cloud detail information")
return cmd
}