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.

84 lines
2.2 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. CompactRevision uint32
  19. }
  20. func NewVolumeInfo(m *master_pb.VolumeInformationMessage) (vi VolumeInfo, err error) {
  21. vi = VolumeInfo{
  22. Id: VolumeId(m.Id),
  23. Size: m.Size,
  24. Collection: m.Collection,
  25. FileCount: int(m.FileCount),
  26. DeleteCount: int(m.DeleteCount),
  27. DeletedByteCount: m.DeletedByteCount,
  28. ReadOnly: m.ReadOnly,
  29. Version: Version(m.Version),
  30. CompactRevision: m.CompactRevision,
  31. }
  32. rp, e := NewReplicaPlacementFromByte(byte(m.ReplicaPlacement))
  33. if e != nil {
  34. return vi, e
  35. }
  36. vi.ReplicaPlacement = rp
  37. vi.Ttl = LoadTTLFromUint32(m.Ttl)
  38. return vi, nil
  39. }
  40. func (vi VolumeInfo) String() string {
  41. return fmt.Sprintf("Id:%d, Size:%d, ReplicaPlacement:%s, Collection:%s, Version:%v, FileCount:%d, DeleteCount:%d, DeletedByteCount:%d, ReadOnly:%v",
  42. vi.Id, vi.Size, vi.ReplicaPlacement, vi.Collection, vi.Version, vi.FileCount, vi.DeleteCount, vi.DeletedByteCount, vi.ReadOnly)
  43. }
  44. func (vi VolumeInfo) ToVolumeInformationMessage() *master_pb.VolumeInformationMessage {
  45. return &master_pb.VolumeInformationMessage{
  46. Id: uint32(vi.Id),
  47. Size: uint64(vi.Size),
  48. Collection: vi.Collection,
  49. FileCount: uint64(vi.FileCount),
  50. DeleteCount: uint64(vi.DeleteCount),
  51. DeletedByteCount: vi.DeletedByteCount,
  52. ReadOnly: vi.ReadOnly,
  53. ReplicaPlacement: uint32(vi.ReplicaPlacement.Byte()),
  54. Version: uint32(vi.Version),
  55. Ttl: vi.Ttl.ToUint32(),
  56. CompactRevision: vi.CompactRevision,
  57. }
  58. }
  59. /*VolumesInfo sorting*/
  60. type volumeInfos []*VolumeInfo
  61. func (vis volumeInfos) Len() int {
  62. return len(vis)
  63. }
  64. func (vis volumeInfos) Less(i, j int) bool {
  65. return vis[i].Id < vis[j].Id
  66. }
  67. func (vis volumeInfos) Swap(i, j int) {
  68. vis[i], vis[j] = vis[j], vis[i]
  69. }
  70. func sortVolumeInfos(vis volumeInfos) {
  71. sort.Sort(vis)
  72. }