|
@ -7,6 +7,7 @@ import ( |
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" |
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb" |
|
|
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding" |
|
|
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding" |
|
|
"golang.org/x/exp/slices" |
|
|
"golang.org/x/exp/slices" |
|
|
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
|
"io" |
|
|
"io" |
|
|
) |
|
|
) |
|
@ -16,6 +17,9 @@ func init() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type commandVolumeList struct { |
|
|
type commandVolumeList struct { |
|
|
|
|
|
collectionPattern *string |
|
|
|
|
|
readonly *bool |
|
|
|
|
|
volumeId *uint64 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (c *commandVolumeList) Name() string { |
|
|
func (c *commandVolumeList) Name() string { |
|
@ -34,6 +38,10 @@ func (c *commandVolumeList) Do(args []string, commandEnv *CommandEnv, writer io. |
|
|
|
|
|
|
|
|
volumeListCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) |
|
|
volumeListCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) |
|
|
verbosityLevel := volumeListCommand.Int("v", 5, "verbose mode: 0, 1, 2, 3, 4, 5") |
|
|
verbosityLevel := volumeListCommand.Int("v", 5, "verbose mode: 0, 1, 2, 3, 4, 5") |
|
|
|
|
|
c.collectionPattern = volumeListCommand.String("collectionPattern", "", "match with wildcard characters '*' and '?'") |
|
|
|
|
|
c.readonly = volumeListCommand.Bool("readonly", false, "show only readonly") |
|
|
|
|
|
c.volumeId = volumeListCommand.Uint64("volumeId", 0, "show only volume id") |
|
|
|
|
|
|
|
|
if err = volumeListCommand.Parse(args); err != nil { |
|
|
if err = volumeListCommand.Parse(args); err != nil { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
@ -44,7 +52,7 @@ func (c *commandVolumeList) Do(args []string, commandEnv *CommandEnv, writer io. |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
writeTopologyInfo(writer, topologyInfo, volumeSizeLimitMb, *verbosityLevel) |
|
|
|
|
|
|
|
|
c.writeTopologyInfo(writer, topologyInfo, volumeSizeLimitMb, *verbosityLevel) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -65,53 +73,71 @@ func diskInfoToString(diskInfo *master_pb.DiskInfo) string { |
|
|
return buf.String() |
|
|
return buf.String() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo, volumeSizeLimitMb uint64, verbosityLevel int) statistics { |
|
|
|
|
|
|
|
|
func (c *commandVolumeList) writeTopologyInfo(writer io.Writer, t *master_pb.TopologyInfo, volumeSizeLimitMb uint64, verbosityLevel int) statistics { |
|
|
output(verbosityLevel >= 0, writer, "Topology volumeSizeLimit:%d MB%s\n", volumeSizeLimitMb, diskInfosToString(t.DiskInfos)) |
|
|
output(verbosityLevel >= 0, writer, "Topology volumeSizeLimit:%d MB%s\n", volumeSizeLimitMb, diskInfosToString(t.DiskInfos)) |
|
|
slices.SortFunc(t.DataCenterInfos, func(a, b *master_pb.DataCenterInfo) bool { |
|
|
slices.SortFunc(t.DataCenterInfos, func(a, b *master_pb.DataCenterInfo) bool { |
|
|
return a.Id < b.Id |
|
|
return a.Id < b.Id |
|
|
}) |
|
|
}) |
|
|
var s statistics |
|
|
var s statistics |
|
|
for _, dc := range t.DataCenterInfos { |
|
|
for _, dc := range t.DataCenterInfos { |
|
|
s = s.plus(writeDataCenterInfo(writer, dc, verbosityLevel)) |
|
|
|
|
|
|
|
|
s = s.plus(c.writeDataCenterInfo(writer, dc, verbosityLevel)) |
|
|
} |
|
|
} |
|
|
output(verbosityLevel >= 0, writer, "%+v \n", s) |
|
|
output(verbosityLevel >= 0, writer, "%+v \n", s) |
|
|
return s |
|
|
return s |
|
|
} |
|
|
} |
|
|
func writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo, verbosityLevel int) statistics { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *commandVolumeList) writeDataCenterInfo(writer io.Writer, t *master_pb.DataCenterInfo, verbosityLevel int) statistics { |
|
|
output(verbosityLevel >= 1, writer, " DataCenter %s%s\n", t.Id, diskInfosToString(t.DiskInfos)) |
|
|
output(verbosityLevel >= 1, writer, " DataCenter %s%s\n", t.Id, diskInfosToString(t.DiskInfos)) |
|
|
var s statistics |
|
|
var s statistics |
|
|
slices.SortFunc(t.RackInfos, func(a, b *master_pb.RackInfo) bool { |
|
|
slices.SortFunc(t.RackInfos, func(a, b *master_pb.RackInfo) bool { |
|
|
return a.Id < b.Id |
|
|
return a.Id < b.Id |
|
|
}) |
|
|
}) |
|
|
for _, r := range t.RackInfos { |
|
|
for _, r := range t.RackInfos { |
|
|
s = s.plus(writeRackInfo(writer, r, verbosityLevel)) |
|
|
|
|
|
|
|
|
s = s.plus(c.writeRackInfo(writer, r, verbosityLevel)) |
|
|
} |
|
|
} |
|
|
output(verbosityLevel >= 1, writer, " DataCenter %s %+v \n", t.Id, s) |
|
|
output(verbosityLevel >= 1, writer, " DataCenter %s %+v \n", t.Id, s) |
|
|
return s |
|
|
return s |
|
|
} |
|
|
} |
|
|
func writeRackInfo(writer io.Writer, t *master_pb.RackInfo, verbosityLevel int) statistics { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *commandVolumeList) writeRackInfo(writer io.Writer, t *master_pb.RackInfo, verbosityLevel int) statistics { |
|
|
output(verbosityLevel >= 2, writer, " Rack %s%s\n", t.Id, diskInfosToString(t.DiskInfos)) |
|
|
output(verbosityLevel >= 2, writer, " Rack %s%s\n", t.Id, diskInfosToString(t.DiskInfos)) |
|
|
var s statistics |
|
|
var s statistics |
|
|
slices.SortFunc(t.DataNodeInfos, func(a, b *master_pb.DataNodeInfo) bool { |
|
|
slices.SortFunc(t.DataNodeInfos, func(a, b *master_pb.DataNodeInfo) bool { |
|
|
return a.Id < b.Id |
|
|
return a.Id < b.Id |
|
|
}) |
|
|
}) |
|
|
for _, dn := range t.DataNodeInfos { |
|
|
for _, dn := range t.DataNodeInfos { |
|
|
s = s.plus(writeDataNodeInfo(writer, dn, verbosityLevel)) |
|
|
|
|
|
|
|
|
s = s.plus(c.writeDataNodeInfo(writer, dn, verbosityLevel)) |
|
|
} |
|
|
} |
|
|
output(verbosityLevel >= 2, writer, " Rack %s %+v \n", t.Id, s) |
|
|
output(verbosityLevel >= 2, writer, " Rack %s %+v \n", t.Id, s) |
|
|
return s |
|
|
return s |
|
|
} |
|
|
} |
|
|
func writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo, verbosityLevel int) statistics { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *commandVolumeList) writeDataNodeInfo(writer io.Writer, t *master_pb.DataNodeInfo, verbosityLevel int) statistics { |
|
|
output(verbosityLevel >= 3, writer, " DataNode %s%s\n", t.Id, diskInfosToString(t.DiskInfos)) |
|
|
output(verbosityLevel >= 3, writer, " DataNode %s%s\n", t.Id, diskInfosToString(t.DiskInfos)) |
|
|
var s statistics |
|
|
var s statistics |
|
|
for _, diskInfo := range t.DiskInfos { |
|
|
for _, diskInfo := range t.DiskInfos { |
|
|
s = s.plus(writeDiskInfo(writer, diskInfo, verbosityLevel)) |
|
|
|
|
|
|
|
|
s = s.plus(c.writeDiskInfo(writer, diskInfo, verbosityLevel)) |
|
|
} |
|
|
} |
|
|
output(verbosityLevel >= 3, writer, " DataNode %s %+v \n", t.Id, s) |
|
|
output(verbosityLevel >= 3, writer, " DataNode %s %+v \n", t.Id, s) |
|
|
return s |
|
|
return s |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func writeDiskInfo(writer io.Writer, t *master_pb.DiskInfo, verbosityLevel int) statistics { |
|
|
|
|
|
|
|
|
func (c *commandVolumeList) isNotMatchDiskInfo(readOnly bool, collection string, volumeId uint32) bool { |
|
|
|
|
|
if *c.readonly && !readOnly { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
if *c.collectionPattern != "" { |
|
|
|
|
|
if matched, _ := filepath.Match(*c.collectionPattern, collection); !matched { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if *c.volumeId > 0 && *c.volumeId != uint64(volumeId) { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *commandVolumeList) writeDiskInfo(writer io.Writer, t *master_pb.DiskInfo, verbosityLevel int) statistics { |
|
|
var s statistics |
|
|
var s statistics |
|
|
diskType := t.Type |
|
|
diskType := t.Type |
|
|
if diskType == "" { |
|
|
if diskType == "" { |
|
@ -122,9 +148,15 @@ func writeDiskInfo(writer io.Writer, t *master_pb.DiskInfo, verbosityLevel int) |
|
|
return a.Id < b.Id |
|
|
return a.Id < b.Id |
|
|
}) |
|
|
}) |
|
|
for _, vi := range t.VolumeInfos { |
|
|
for _, vi := range t.VolumeInfos { |
|
|
|
|
|
if c.isNotMatchDiskInfo(vi.ReadOnly, vi.Collection, vi.Id) { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
s = s.plus(writeVolumeInformationMessage(writer, vi, verbosityLevel)) |
|
|
s = s.plus(writeVolumeInformationMessage(writer, vi, verbosityLevel)) |
|
|
} |
|
|
} |
|
|
for _, ecShardInfo := range t.EcShardInfos { |
|
|
for _, ecShardInfo := range t.EcShardInfos { |
|
|
|
|
|
if c.isNotMatchDiskInfo(false, ecShardInfo.Collection, ecShardInfo.Id) { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
output(verbosityLevel >= 5, writer, " ec volume id:%v collection:%v shards:%v\n", ecShardInfo.Id, ecShardInfo.Collection, erasure_coding.ShardBits(ecShardInfo.EcIndexBits).ShardIds()) |
|
|
output(verbosityLevel >= 5, writer, " ec volume id:%v collection:%v shards:%v\n", ecShardInfo.Id, ecShardInfo.Collection, erasure_coding.ShardBits(ecShardInfo.EcIndexBits).ShardIds()) |
|
|
} |
|
|
} |
|
|
output(verbosityLevel >= 4, writer, " Disk %s %+v \n", diskType, s) |
|
|
output(verbosityLevel >= 4, writer, " Disk %s %+v \n", diskType, s) |
|
|