2019-03-16 20:43:16 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2019-03-19 12:19:37 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2022-03-05 02:47:44 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
2019-03-16 20:43:16 +00:00
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 08:30:24 +00:00
|
|
|
Commands = append(Commands, &commandCollectionList{})
|
2019-03-16 20:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type commandCollectionList struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandCollectionList) Name() string {
|
|
|
|
return "collection.list"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandCollectionList) Help() string {
|
2019-03-23 18:54:26 +00:00
|
|
|
return `list all collections`
|
2019-03-16 20:43:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 22:49:46 +00:00
|
|
|
type CollectionInfo struct {
|
2022-03-05 02:47:44 +00:00
|
|
|
FileCount float64
|
|
|
|
DeleteCount float64
|
|
|
|
DeletedByteCount float64
|
|
|
|
Size float64
|
2021-07-30 22:49:46 +00:00
|
|
|
VolumeCount int
|
|
|
|
}
|
|
|
|
|
2019-06-05 08:30:24 +00:00
|
|
|
func (c *commandCollectionList) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-03-16 20:43:16 +00:00
|
|
|
|
2019-05-30 16:27:23 +00:00
|
|
|
collections, err := ListCollectionNames(commandEnv, true, true)
|
2019-05-06 05:21:28 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-08 08:53:55 +00:00
|
|
|
topologyInfo, _, err := collectTopologyInfo(commandEnv, 0)
|
2021-07-30 22:49:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
collectionInfos := make(map[string]*CollectionInfo)
|
|
|
|
|
2022-01-21 08:16:50 +00:00
|
|
|
collectCollectionInfo(topologyInfo, collectionInfos)
|
2021-07-30 22:49:46 +00:00
|
|
|
|
2019-05-06 05:21:28 +00:00
|
|
|
for _, c := range collections {
|
2021-07-30 22:49:46 +00:00
|
|
|
cif, found := collectionInfos[c]
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
2022-03-05 02:47:44 +00:00
|
|
|
fmt.Fprintf(writer, "collection:\"%s\"\tvolumeCount:%d\tsize:%.0f\tfileCount:%.0f\tdeletedBytes:%.0f\tdeletion:%.0f\n", c, cif.VolumeCount, cif.Size, cif.FileCount, cif.DeletedByteCount, cif.DeleteCount)
|
2019-05-06 05:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(writer, "Total %d collections.\n", len(collections))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-05 08:30:24 +00:00
|
|
|
func ListCollectionNames(commandEnv *CommandEnv, includeNormalVolumes, includeEcVolumes bool) (collections []string, err error) {
|
2019-03-19 12:19:37 +00:00
|
|
|
var resp *master_pb.CollectionListResponse
|
2021-12-26 08:15:03 +00:00
|
|
|
err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
|
2020-02-26 05:50:12 +00:00
|
|
|
resp, err = client.CollectionList(context.Background(), &master_pb.CollectionListRequest{
|
2019-05-30 16:27:23 +00:00
|
|
|
IncludeNormalVolumes: includeNormalVolumes,
|
|
|
|
IncludeEcVolumes: includeEcVolumes,
|
|
|
|
})
|
2019-03-19 12:19:37 +00:00
|
|
|
return err
|
|
|
|
})
|
2019-03-16 20:43:16 +00:00
|
|
|
if err != nil {
|
2019-05-06 05:21:28 +00:00
|
|
|
return
|
2019-03-16 20:43:16 +00:00
|
|
|
}
|
|
|
|
for _, c := range resp.Collections {
|
2019-05-06 05:21:28 +00:00
|
|
|
collections = append(collections, c.Name)
|
2019-03-16 20:43:16 +00:00
|
|
|
}
|
2019-05-06 05:21:28 +00:00
|
|
|
return
|
2019-03-16 20:43:16 +00:00
|
|
|
}
|
2021-07-30 22:49:46 +00:00
|
|
|
|
|
|
|
func addToCollection(collectionInfos map[string]*CollectionInfo, vif *master_pb.VolumeInformationMessage) {
|
|
|
|
c := vif.Collection
|
|
|
|
cif, found := collectionInfos[c]
|
|
|
|
if !found {
|
|
|
|
cif = &CollectionInfo{}
|
|
|
|
collectionInfos[c] = cif
|
|
|
|
}
|
2022-03-05 02:47:44 +00:00
|
|
|
replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(vif.ReplicaPlacement))
|
|
|
|
copyCount := float64(replicaPlacement.GetCopyCount())
|
|
|
|
cif.Size += float64(vif.Size) / copyCount
|
|
|
|
cif.DeleteCount += float64(vif.DeleteCount) / copyCount
|
|
|
|
cif.FileCount += float64(vif.FileCount) / copyCount
|
|
|
|
cif.DeletedByteCount += float64(vif.DeletedByteCount) / copyCount
|
2021-07-30 22:49:46 +00:00
|
|
|
cif.VolumeCount++
|
|
|
|
}
|
|
|
|
|
2022-01-21 08:16:50 +00:00
|
|
|
func collectCollectionInfo(t *master_pb.TopologyInfo, collectionInfos map[string]*CollectionInfo) {
|
2021-07-30 22:49:46 +00:00
|
|
|
for _, dc := range t.DataCenterInfos {
|
|
|
|
for _, r := range dc.RackInfos {
|
|
|
|
for _, dn := range r.DataNodeInfos {
|
|
|
|
for _, diskInfo := range dn.DiskInfos {
|
|
|
|
for _, vi := range diskInfo.VolumeInfos {
|
|
|
|
addToCollection(collectionInfos, vi)
|
|
|
|
}
|
|
|
|
//for _, ecShardInfo := range diskInfo.EcShardInfos {
|
|
|
|
//
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|