seaweedfs/weed/storage/volume_info.go

101 lines
2.7 KiB
Go
Raw Normal View History

2012-08-24 14:24:32 +08:00
package storage
import (
"fmt"
"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"
2019-04-19 12:43:36 +08:00
"github.com/chrislusf/seaweedfs/weed/storage/needle"
)
2012-08-24 14:24:32 +08:00
type VolumeInfo struct {
2019-04-19 12:43:36 +08:00
Id needle.VolumeId
Size uint64
ReplicaPlacement *ReplicaPlacement
2019-04-19 12:43:36 +08:00
Ttl *needle.TTL
2013-11-12 18:21:22 +08:00
Collection string
2019-04-19 12:43:36 +08:00
Version needle.Version
FileCount int
DeleteCount int
DeletedByteCount uint64
ReadOnly bool
CompactRevision uint32
}
2018-05-10 14:11:54 +08:00
func NewVolumeInfo(m *master_pb.VolumeInformationMessage) (vi VolumeInfo, err error) {
vi = VolumeInfo{
2019-04-19 12:43:36 +08:00
Id: needle.VolumeId(m.Id),
2017-01-10 17:01:12 +08:00
Size: m.Size,
Collection: m.Collection,
FileCount: int(m.FileCount),
DeleteCount: int(m.DeleteCount),
DeletedByteCount: m.DeletedByteCount,
ReadOnly: m.ReadOnly,
2019-04-19 12:43:36 +08:00
Version: needle.Version(m.Version),
CompactRevision: m.CompactRevision,
}
2017-01-10 17:01:12 +08:00
rp, e := NewReplicaPlacementFromByte(byte(m.ReplicaPlacement))
if e != nil {
return vi, e
}
vi.ReplicaPlacement = rp
2019-04-19 12:43:36 +08:00
vi.Ttl = needle.LoadTTLFromUint32(m.Ttl)
return vi, nil
}
2019-04-21 02:35:20 +08:00
func NewVolumeInfoFromShort(m *master_pb.VolumeShortInformationMessage) (vi VolumeInfo, err error) {
vi = VolumeInfo{
2019-04-30 11:22:19 +08:00
Id: needle.VolumeId(m.Id),
Collection: m.Collection,
Version: needle.Version(m.Version),
2019-04-21 02:35:20 +08:00
}
rp, e := NewReplicaPlacementFromByte(byte(m.ReplicaPlacement))
if e != nil {
return vi, e
}
vi.ReplicaPlacement = rp
vi.Ttl = needle.LoadTTLFromUint32(m.Ttl)
return vi, nil
}
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)
}
2019-03-18 11:27:08 +08:00
func (vi VolumeInfo) ToVolumeInformationMessage() *master_pb.VolumeInformationMessage {
return &master_pb.VolumeInformationMessage{
Id: uint32(vi.Id),
Size: uint64(vi.Size),
Collection: vi.Collection,
FileCount: uint64(vi.FileCount),
DeleteCount: uint64(vi.DeleteCount),
DeletedByteCount: vi.DeletedByteCount,
ReadOnly: vi.ReadOnly,
ReplicaPlacement: uint32(vi.ReplicaPlacement.Byte()),
Version: uint32(vi.Version),
Ttl: vi.Ttl.ToUint32(),
CompactRevision: vi.CompactRevision,
2019-03-18 11:27:08 +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)
}