2012-08-24 14:24:32 +08:00
|
|
|
package storage
|
|
|
|
|
2014-04-21 17:11:10 +08:00
|
|
|
import (
|
2015-01-08 15:54:50 +08:00
|
|
|
"fmt"
|
2015-04-21 01:16:23 +08:00
|
|
|
"sort"
|
2017-01-10 17:01:12 +08:00
|
|
|
|
2018-05-10 14:11:54 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2014-04-21 17:11:10 +08:00
|
|
|
)
|
2012-08-24 14:24:32 +08:00
|
|
|
|
2012-09-10 15:18:07 +08:00
|
|
|
type VolumeInfo struct {
|
2012-12-04 14:54:08 +08:00
|
|
|
Id VolumeId
|
|
|
|
Size uint64
|
2014-03-03 14:16:54 +08:00
|
|
|
ReplicaPlacement *ReplicaPlacement
|
2014-09-21 03:38:59 +08:00
|
|
|
Ttl *TTL
|
2013-11-12 18:21:22 +08:00
|
|
|
Collection string
|
2012-12-18 08:48:54 +08:00
|
|
|
Version Version
|
2012-12-04 14:54:08 +08:00
|
|
|
FileCount int
|
|
|
|
DeleteCount int
|
|
|
|
DeletedByteCount uint64
|
2013-04-15 10:30:26 +08:00
|
|
|
ReadOnly bool
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|
2014-04-21 17:11:10 +08:00
|
|
|
|
2018-05-10 14:11:54 +08:00
|
|
|
func NewVolumeInfo(m *master_pb.VolumeInformationMessage) (vi VolumeInfo, err error) {
|
2014-04-21 17:11:10 +08:00
|
|
|
vi = VolumeInfo{
|
2017-01-10 17:01:12 +08:00
|
|
|
Id: VolumeId(m.Id),
|
|
|
|
Size: m.Size,
|
|
|
|
Collection: m.Collection,
|
|
|
|
FileCount: int(m.FileCount),
|
|
|
|
DeleteCount: int(m.DeleteCount),
|
|
|
|
DeletedByteCount: m.DeletedByteCount,
|
|
|
|
ReadOnly: m.ReadOnly,
|
|
|
|
Version: Version(m.Version),
|
2014-04-21 17:11:10 +08:00
|
|
|
}
|
2017-01-10 17:01:12 +08:00
|
|
|
rp, e := NewReplicaPlacementFromByte(byte(m.ReplicaPlacement))
|
2014-04-21 17:11:10 +08:00
|
|
|
if e != nil {
|
|
|
|
return vi, e
|
|
|
|
}
|
|
|
|
vi.ReplicaPlacement = rp
|
2017-01-10 17:01:12 +08:00
|
|
|
vi.Ttl = LoadTTLFromUint32(m.Ttl)
|
2014-04-21 17:11:10 +08:00
|
|
|
return vi, nil
|
|
|
|
}
|
2015-01-08 15:54:50 +08:00
|
|
|
|
|
|
|
func (vi VolumeInfo) String() string {
|
2015-01-14 09:04:41 +08:00
|
|
|
return fmt.Sprintf("Id:%d, Size:%d, ReplicaPlacement:%s, Collection:%s, Version:%v, FileCount:%d, DeleteCount:%d, DeletedByteCount:%d, ReadOnly:%v",
|
|
|
|
vi.Id, vi.Size, vi.ReplicaPlacement, vi.Collection, vi.Version, vi.FileCount, vi.DeleteCount, vi.DeletedByteCount, vi.ReadOnly)
|
2015-01-08 15:54:50 +08:00
|
|
|
}
|
2015-04-21 01:16:23 +08:00
|
|
|
|
|
|
|
/*VolumesInfo sorting*/
|
|
|
|
|
|
|
|
type volumeInfos []*VolumeInfo
|
|
|
|
|
|
|
|
func (vis volumeInfos) Len() int {
|
|
|
|
return len(vis)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vis volumeInfos) Less(i, j int) bool {
|
|
|
|
return vis[i].Id < vis[j].Id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vis volumeInfos) Swap(i, j int) {
|
|
|
|
vis[i], vis[j] = vis[j], vis[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortVolumeInfos(vis volumeInfos) {
|
|
|
|
sort.Sort(vis)
|
|
|
|
}
|