You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.1 KiB

  1. package storage
  2. import (
  3. "fmt"
  4. "sort"
  5. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  6. )
  7. type VolumeInfo struct {
  8. Id VolumeId
  9. Size uint64
  10. ReplicaPlacement *ReplicaPlacement
  11. Ttl *TTL
  12. Collection string
  13. Version Version
  14. FileCount int
  15. DeleteCount int
  16. DeletedByteCount uint64
  17. ReadOnly bool
  18. }
  19. func NewVolumeInfo(m *master_pb.VolumeInformationMessage) (vi VolumeInfo, err error) {
  20. vi = VolumeInfo{
  21. Id: VolumeId(m.Id),
  22. Size: m.Size,
  23. Collection: m.Collection,
  24. FileCount: int(m.FileCount),
  25. DeleteCount: int(m.DeleteCount),
  26. DeletedByteCount: m.DeletedByteCount,
  27. ReadOnly: m.ReadOnly,
  28. Version: Version(m.Version),
  29. }
  30. rp, e := NewReplicaPlacementFromByte(byte(m.ReplicaPlacement))
  31. if e != nil {
  32. return vi, e
  33. }
  34. vi.ReplicaPlacement = rp
  35. vi.Ttl = LoadTTLFromUint32(m.Ttl)
  36. return vi, nil
  37. }
  38. func (vi VolumeInfo) String() string {
  39. return fmt.Sprintf("Id:%d, Size:%d, ReplicaPlacement:%s, Collection:%s, Version:%v, FileCount:%d, DeleteCount:%d, DeletedByteCount:%d, ReadOnly:%v",
  40. vi.Id, vi.Size, vi.ReplicaPlacement, vi.Collection, vi.Version, vi.FileCount, vi.DeleteCount, vi.DeletedByteCount, vi.ReadOnly)
  41. }
  42. func (vi VolumeInfo) ToVolumeInformationMessage() *master_pb.VolumeInformationMessage {
  43. return &master_pb.VolumeInformationMessage{
  44. Id: uint32(vi.Id),
  45. Size: uint64(vi.Size),
  46. Collection: vi.Collection,
  47. FileCount: uint64(vi.FileCount),
  48. DeleteCount: uint64(vi.DeleteCount),
  49. DeletedByteCount: vi.DeletedByteCount,
  50. ReadOnly: vi.ReadOnly,
  51. ReplicaPlacement: uint32(vi.ReplicaPlacement.Byte()),
  52. Version: uint32(vi.Version),
  53. Ttl: vi.Ttl.ToUint32(),
  54. }
  55. }
  56. /*VolumesInfo sorting*/
  57. type volumeInfos []*VolumeInfo
  58. func (vis volumeInfos) Len() int {
  59. return len(vis)
  60. }
  61. func (vis volumeInfos) Less(i, j int) bool {
  62. return vis[i].Id < vis[j].Id
  63. }
  64. func (vis volumeInfos) Swap(i, j int) {
  65. vis[i], vis[j] = vis[j], vis[i]
  66. }
  67. func sortVolumeInfos(vis volumeInfos) {
  68. sort.Sort(vis)
  69. }