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.

65 lines
1.6 KiB

  1. package storage
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/operation"
  5. "sort"
  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 *operation.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. /*VolumesInfo sorting*/
  43. type volumeInfos []*VolumeInfo
  44. func (vis volumeInfos) Len() int {
  45. return len(vis)
  46. }
  47. func (vis volumeInfos) Less(i, j int) bool {
  48. return vis[i].Id < vis[j].Id
  49. }
  50. func (vis volumeInfos) Swap(i, j int) {
  51. vis[i], vis[j] = vis[j], vis[i]
  52. }
  53. func sortVolumeInfos(vis volumeInfos) {
  54. sort.Sort(vis)
  55. }