2019-03-18 11:27:08 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2019-05-25 04:28:44 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
|
|
|
|
2019-03-18 11:27:08 +08:00
|
|
|
"io"
|
2019-05-06 11:23:50 +08:00
|
|
|
"sort"
|
2019-03-18 11:27:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 16:30:24 +08:00
|
|
|
Commands = append(Commands, &commandVolumeList{})
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type commandVolumeList struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandVolumeList) Name() string {
|
|
|
|
return "volume.list"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandVolumeList) Help() string {
|
2019-03-24 02:54:26 +08:00
|
|
|
return `list all volumes
|
|
|
|
|
|
|
|
This command list all volumes as a tree of dataCenter > rack > dataNode > volume.
|
|
|
|
|
|
|
|
`
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
func (c *commandVolumeList) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-03-18 11:27:08 +08:00
|
|
|
|
2019-03-19 20:19:37 +08:00
|
|
|
var resp *master_pb.VolumeListResponse
|
2019-03-20 14:01:23 +08:00
|
|
|
ctx := context.Background()
|
2019-06-05 16:30:24 +08:00
|
|
|
err = commandEnv.MasterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
|
2019-03-19 20:19:37 +08:00
|
|
|
resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{})
|
|
|
|
return err
|
|
|
|
})
|
2019-03-18 11:27:08 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-06 11:23:50 +08:00
|
|
|
writeTopologyInfo(writer, resp.TopologyInfo, resp.VolumeSizeLimitMb)
|
2019-03-18 11:27:08 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-06 11:23:50 +08:00
|
|
|
func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo, volumeSizeLimitMb uint64) statistics {
|
2019-12-04 13:36:42 +08:00
|
|
|
fmt.Fprintf(writer, "Topology volume:%d/%d active:%d free:%d remote:%d volumeSizeLimit:%d MB\n", t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount, t.RemoteVolumeCount, volumeSizeLimitMb)
|
2019-05-06 11:23:50 +08:00
|
|
|
sort.Slice(t.DataCenterInfos, func(i, j int) bool {
|
|
|
|
return t.DataCenterInfos[i].Id < t.DataCenterInfos[j].Id
|
|
|
|
})
|
2019-04-07 00:25:29 +08:00
|
|
|
var s statistics
|
2019-03-18 11:27:08 +08:00
|
|
|
for _, dc := range t.DataCenterInfos {
|
2019-04-07 00:25:29 +08:00
|
|
|
s = s.plus(writeDataCenterInfo(writer, dc))
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
2019-04-07 00:25:29 +08:00
|
|
|
fmt.Fprintf(writer, "%+v \n", s)
|
|
|
|
return s
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
2019-04-07 02:12:35 +08:00
|
|
|
func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo) statistics {
|
2019-12-04 13:36:42 +08:00
|
|
|
fmt.Fprintf(writer, " DataCenter %s volume:%d/%d active:%d free:%d remote:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount, t.RemoteVolumeCount)
|
2019-04-07 00:25:29 +08:00
|
|
|
var s statistics
|
2019-05-06 11:23:50 +08:00
|
|
|
sort.Slice(t.RackInfos, func(i, j int) bool {
|
|
|
|
return t.RackInfos[i].Id < t.RackInfos[j].Id
|
|
|
|
})
|
2019-03-18 11:27:08 +08:00
|
|
|
for _, r := range t.RackInfos {
|
2019-04-07 00:25:29 +08:00
|
|
|
s = s.plus(writeRackInfo(writer, r))
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
2019-04-07 00:25:29 +08:00
|
|
|
fmt.Fprintf(writer, " DataCenter %s %+v \n", t.Id, s)
|
|
|
|
return s
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
2019-04-07 02:12:35 +08:00
|
|
|
func writeRackInfo(writer io.Writer, t *master_pb.RackInfo) statistics {
|
2019-12-04 13:36:42 +08:00
|
|
|
fmt.Fprintf(writer, " Rack %s volume:%d/%d active:%d free:%d remote:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount, t.RemoteVolumeCount)
|
2019-04-07 00:25:29 +08:00
|
|
|
var s statistics
|
2019-05-06 11:23:50 +08:00
|
|
|
sort.Slice(t.DataNodeInfos, func(i, j int) bool {
|
|
|
|
return t.DataNodeInfos[i].Id < t.DataNodeInfos[j].Id
|
|
|
|
})
|
2019-03-18 11:27:08 +08:00
|
|
|
for _, dn := range t.DataNodeInfos {
|
2019-04-07 00:25:29 +08:00
|
|
|
s = s.plus(writeDataNodeInfo(writer, dn))
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
2019-04-07 00:25:29 +08:00
|
|
|
fmt.Fprintf(writer, " Rack %s %+v \n", t.Id, s)
|
|
|
|
return s
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
2019-04-07 02:12:35 +08:00
|
|
|
func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) statistics {
|
2019-12-04 13:36:42 +08:00
|
|
|
fmt.Fprintf(writer, " DataNode %s volume:%d/%d active:%d free:%d remote:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount, t.RemoteVolumeCount)
|
2019-04-07 00:25:29 +08:00
|
|
|
var s statistics
|
2019-05-06 11:23:50 +08:00
|
|
|
sort.Slice(t.VolumeInfos, func(i, j int) bool {
|
|
|
|
return t.VolumeInfos[i].Id < t.VolumeInfos[j].Id
|
|
|
|
})
|
2019-03-18 11:27:08 +08:00
|
|
|
for _, vi := range t.VolumeInfos {
|
2019-04-07 00:25:29 +08:00
|
|
|
s = s.plus(writeVolumeInformationMessage(writer, vi))
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
2019-05-25 02:52:23 +08:00
|
|
|
for _, ecShardInfo := range t.EcShardInfos {
|
2019-05-25 04:28:44 +08:00
|
|
|
fmt.Fprintf(writer, " ec volume id:%v collection:%v shards:%v\n", ecShardInfo.Id, ecShardInfo.Collection, erasure_coding.ShardBits(ecShardInfo.EcIndexBits).ShardIds())
|
2019-05-25 02:52:23 +08:00
|
|
|
}
|
2019-04-07 00:25:29 +08:00
|
|
|
fmt.Fprintf(writer, " DataNode %s %+v \n", t.Id, s)
|
|
|
|
return s
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|
2019-04-07 00:25:29 +08:00
|
|
|
func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) statistics {
|
2019-03-18 11:27:08 +08:00
|
|
|
fmt.Fprintf(writer, " volume %+v \n", t)
|
2019-09-29 14:17:37 +08:00
|
|
|
return newStatistics(t)
|
2019-04-07 00:25:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type statistics struct {
|
|
|
|
Size uint64
|
|
|
|
FileCount uint64
|
|
|
|
DeletedFileCount uint64
|
|
|
|
DeletedBytes uint64
|
|
|
|
}
|
|
|
|
|
2019-09-29 14:17:37 +08:00
|
|
|
func newStatistics(t *master_pb.VolumeInformationMessage) statistics {
|
2019-04-07 00:25:29 +08:00
|
|
|
return statistics{
|
|
|
|
Size: t.Size,
|
|
|
|
FileCount: t.FileCount,
|
|
|
|
DeletedFileCount: t.DeleteCount,
|
|
|
|
DeletedBytes: t.DeletedByteCount,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s statistics) plus(t statistics) statistics {
|
|
|
|
return statistics{
|
|
|
|
Size: s.Size + t.Size,
|
|
|
|
FileCount: s.FileCount + t.FileCount,
|
|
|
|
DeletedFileCount: s.DeletedFileCount + t.DeletedFileCount,
|
|
|
|
DeletedBytes: s.DeletedBytes + t.DeletedBytes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s statistics) String() string {
|
2019-04-07 02:12:35 +08:00
|
|
|
if s.DeletedFileCount > 0 {
|
2019-04-07 00:25:29 +08:00
|
|
|
return fmt.Sprintf("total size:%d file_count:%d deleted_file:%d deleted_bytes:%d", s.Size, s.FileCount, s.DeletedFileCount, s.DeletedBytes)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("total size:%d file_count:%d", s.Size, s.FileCount)
|
2019-03-18 11:27:08 +08:00
|
|
|
}
|