1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
package shell
import (
"context"
"fmt"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
"io"
)
func init() {
commands = append(commands, &commandVolumeList{})
}
type commandVolumeList struct {
}
func (c *commandVolumeList) Name() string {
return "volume.list"
}
func (c *commandVolumeList) Help() string {
return `list all volumes
This command list all volumes as a tree of dataCenter > rack > dataNode > volume.
`
}
func (c *commandVolumeList) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
var resp *master_pb.VolumeListResponse
ctx := context.Background()
err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
resp, err = client.VolumeList(ctx, &master_pb.VolumeListRequest{})
return err
})
if err != nil {
return err
}
writeTopologyInfo(writer, resp.TopologyInfo)
return nil
}
func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo) statistics {
fmt.Fprintf(writer, "Topology volume:%d/%d active:%d free:%d\n", t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
var s statistics
for _, dc := range t.DataCenterInfos {
s = s.plus(writeDataCenterInfo(writer, dc))
}
fmt.Fprintf(writer, "%+v \n", s)
return s
}
func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo) statistics {
fmt.Fprintf(writer, " DataCenter %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
var s statistics
for _, r := range t.RackInfos {
s = s.plus(writeRackInfo(writer, r))
}
fmt.Fprintf(writer, " DataCenter %s %+v \n", t.Id, s)
return s
}
func writeRackInfo(writer io.Writer, t *master_pb.RackInfo) statistics {
fmt.Fprintf(writer, " Rack %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
var s statistics
for _, dn := range t.DataNodeInfos {
s = s.plus(writeDataNodeInfo(writer, dn))
}
fmt.Fprintf(writer, " Rack %s %+v \n", t.Id, s)
return s
}
func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo) statistics {
fmt.Fprintf(writer, " DataNode %s volume:%d/%d active:%d free:%d\n", t.Id, t.VolumeCount, t.MaxVolumeCount, t.ActiveVolumeCount, t.FreeVolumeCount)
var s statistics
for _, vi := range t.VolumeInfos {
s = s.plus(writeVolumeInformationMessage(writer, vi))
}
fmt.Fprintf(writer, " DataNode %s %+v \n", t.Id, s)
return s
}
func writeVolumeInformationMessage(writer io.Writer, t *master_pb.VolumeInformationMessage) statistics {
fmt.Fprintf(writer, " volume %+v \n", t)
return newStatiscis(t)
}
type statistics struct {
Size uint64
FileCount uint64
DeletedFileCount uint64
DeletedBytes uint64
}
func newStatiscis(t *master_pb.VolumeInformationMessage) statistics {
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 {
if s.DeletedFileCount > 0 {
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)
}
|