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.

85 lines
2.3 KiB

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