2012-08-24 06:24:32 +00:00
|
|
|
package storage
|
|
|
|
|
2014-04-21 09:11:10 +00:00
|
|
|
import (
|
2015-01-08 07:54:50 +00:00
|
|
|
"fmt"
|
2015-04-20 17:16:23 +00:00
|
|
|
"sort"
|
2017-01-10 09:01:12 +00:00
|
|
|
|
2018-05-10 06:11:54 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2019-04-19 04:43:36 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
2019-12-23 20:48:20 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
2014-04-21 09:11:10 +00:00
|
|
|
)
|
2012-08-24 06:24:32 +00:00
|
|
|
|
2012-09-10 07:18:07 +00:00
|
|
|
type VolumeInfo struct {
|
2019-12-03 07:23:54 +00:00
|
|
|
Id needle.VolumeId
|
|
|
|
Size uint64
|
2019-12-23 20:48:20 +00:00
|
|
|
ReplicaPlacement *super_block.ReplicaPlacement
|
2019-12-03 07:23:54 +00:00
|
|
|
Ttl *needle.TTL
|
|
|
|
Collection string
|
|
|
|
Version needle.Version
|
|
|
|
FileCount int
|
|
|
|
DeleteCount int
|
|
|
|
DeletedByteCount uint64
|
|
|
|
ReadOnly bool
|
|
|
|
CompactRevision uint32
|
|
|
|
ModifiedAtSecond int64
|
|
|
|
RemoteStorageName string
|
|
|
|
RemoteStorageKey string
|
2012-09-10 07:18:07 +00:00
|
|
|
}
|
2014-04-21 09:11:10 +00:00
|
|
|
|
2018-05-10 06:11:54 +00:00
|
|
|
func NewVolumeInfo(m *master_pb.VolumeInformationMessage) (vi VolumeInfo, err error) {
|
2014-04-21 09:11:10 +00:00
|
|
|
vi = VolumeInfo{
|
2019-12-03 07:38:56 +00:00
|
|
|
Id: needle.VolumeId(m.Id),
|
|
|
|
Size: m.Size,
|
|
|
|
Collection: m.Collection,
|
|
|
|
FileCount: int(m.FileCount),
|
|
|
|
DeleteCount: int(m.DeleteCount),
|
|
|
|
DeletedByteCount: m.DeletedByteCount,
|
|
|
|
ReadOnly: m.ReadOnly,
|
|
|
|
Version: needle.Version(m.Version),
|
|
|
|
CompactRevision: m.CompactRevision,
|
|
|
|
ModifiedAtSecond: m.ModifiedAtSecond,
|
|
|
|
RemoteStorageName: m.RemoteStorageName,
|
|
|
|
RemoteStorageKey: m.RemoteStorageKey,
|
2014-04-21 09:11:10 +00:00
|
|
|
}
|
2019-12-23 20:48:20 +00:00
|
|
|
rp, e := super_block.NewReplicaPlacementFromByte(byte(m.ReplicaPlacement))
|
2014-04-21 09:11:10 +00:00
|
|
|
if e != nil {
|
|
|
|
return vi, e
|
|
|
|
}
|
|
|
|
vi.ReplicaPlacement = rp
|
2019-04-19 04:43:36 +00:00
|
|
|
vi.Ttl = needle.LoadTTLFromUint32(m.Ttl)
|
2014-04-21 09:11:10 +00:00
|
|
|
return vi, nil
|
|
|
|
}
|
2015-01-08 07:54:50 +00:00
|
|
|
|
2019-04-20 18:35:20 +00:00
|
|
|
func NewVolumeInfoFromShort(m *master_pb.VolumeShortInformationMessage) (vi VolumeInfo, err error) {
|
|
|
|
vi = VolumeInfo{
|
2019-04-30 03:22:19 +00:00
|
|
|
Id: needle.VolumeId(m.Id),
|
|
|
|
Collection: m.Collection,
|
|
|
|
Version: needle.Version(m.Version),
|
2019-04-20 18:35:20 +00:00
|
|
|
}
|
2019-12-23 20:48:20 +00:00
|
|
|
rp, e := super_block.NewReplicaPlacementFromByte(byte(m.ReplicaPlacement))
|
2019-04-20 18:35:20 +00:00
|
|
|
if e != nil {
|
|
|
|
return vi, e
|
|
|
|
}
|
|
|
|
vi.ReplicaPlacement = rp
|
|
|
|
vi.Ttl = needle.LoadTTLFromUint32(m.Ttl)
|
|
|
|
return vi, nil
|
|
|
|
}
|
|
|
|
|
2019-12-04 05:36:42 +00:00
|
|
|
func (vi VolumeInfo) IsRemote() bool {
|
|
|
|
return vi.RemoteStorageName != ""
|
|
|
|
}
|
|
|
|
|
2015-01-08 07:54:50 +00:00
|
|
|
func (vi VolumeInfo) String() string {
|
2015-01-14 01:04:41 +00: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 07:54:50 +00:00
|
|
|
}
|
2015-04-20 17:16:23 +00:00
|
|
|
|
2019-03-18 03:27:08 +00:00
|
|
|
func (vi VolumeInfo) ToVolumeInformationMessage() *master_pb.VolumeInformationMessage {
|
|
|
|
return &master_pb.VolumeInformationMessage{
|
2019-12-03 07:38:56 +00:00
|
|
|
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,
|
|
|
|
ModifiedAtSecond: vi.ModifiedAtSecond,
|
|
|
|
RemoteStorageName: vi.RemoteStorageName,
|
|
|
|
RemoteStorageKey: vi.RemoteStorageKey,
|
2019-03-18 03:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-20 17:16:23 +00: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)
|
|
|
|
}
|