structs.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package topology
  2. import (
  3. "sync"
  4. "time"
  5. "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
  6. )
  7. // TaskSource represents a single source in a multi-source task (for replicated volume cleanup)
  8. type TaskSource struct {
  9. SourceServer string `json:"source_server"`
  10. SourceDisk uint32 `json:"source_disk"`
  11. StorageChange StorageSlotChange `json:"storage_change"` // Storage impact on this source
  12. EstimatedSize int64 `json:"estimated_size"` // Estimated size for this source
  13. }
  14. // TaskDestination represents a single destination in a multi-destination task
  15. type TaskDestination struct {
  16. TargetServer string `json:"target_server"`
  17. TargetDisk uint32 `json:"target_disk"`
  18. StorageChange StorageSlotChange `json:"storage_change"` // Storage impact on this destination
  19. EstimatedSize int64 `json:"estimated_size"` // Estimated size for this destination
  20. }
  21. // taskState represents the current state of tasks affecting the topology (internal)
  22. // Uses unified multi-source/multi-destination design:
  23. // - Single-source tasks (balance, vacuum, replication): 1 source, 1 destination
  24. // - Multi-source EC tasks (replicated volumes): N sources, M destinations
  25. type taskState struct {
  26. VolumeID uint32 `json:"volume_id"`
  27. TaskType TaskType `json:"task_type"`
  28. Status TaskStatus `json:"status"`
  29. StartedAt time.Time `json:"started_at"`
  30. CompletedAt time.Time `json:"completed_at,omitempty"`
  31. EstimatedSize int64 `json:"estimated_size"` // Total estimated size of task
  32. // Unified source and destination arrays (always used)
  33. Sources []TaskSource `json:"sources"` // Source locations (1+ for all task types)
  34. Destinations []TaskDestination `json:"destinations"` // Destination locations (1+ for all task types)
  35. }
  36. // DiskInfo represents a disk with its current state and ongoing tasks (public for external access)
  37. type DiskInfo struct {
  38. NodeID string `json:"node_id"`
  39. DiskID uint32 `json:"disk_id"`
  40. DiskType string `json:"disk_type"`
  41. DataCenter string `json:"data_center"`
  42. Rack string `json:"rack"`
  43. DiskInfo *master_pb.DiskInfo `json:"disk_info"`
  44. LoadCount int `json:"load_count"` // Number of active tasks
  45. }
  46. // activeDisk represents internal disk state (private)
  47. type activeDisk struct {
  48. *DiskInfo
  49. pendingTasks []*taskState
  50. assignedTasks []*taskState
  51. recentTasks []*taskState // Completed in last N seconds
  52. }
  53. // activeNode represents a node with its disks (private)
  54. type activeNode struct {
  55. nodeID string
  56. dataCenter string
  57. rack string
  58. nodeInfo *master_pb.DataNodeInfo
  59. disks map[uint32]*activeDisk // DiskID -> activeDisk
  60. }
  61. // ActiveTopology provides a real-time view of cluster state with task awareness
  62. type ActiveTopology struct {
  63. // Core topology from master
  64. topologyInfo *master_pb.TopologyInfo
  65. lastUpdated time.Time
  66. // Structured topology for easy access (private)
  67. nodes map[string]*activeNode // NodeID -> activeNode
  68. disks map[string]*activeDisk // "NodeID:DiskID" -> activeDisk
  69. // Performance indexes for O(1) lookups (private)
  70. volumeIndex map[uint32][]string // VolumeID -> list of "NodeID:DiskID" where volume replicas exist
  71. ecShardIndex map[uint32][]string // VolumeID -> list of "NodeID:DiskID" where EC shards exist
  72. // Task states affecting the topology (private)
  73. pendingTasks map[string]*taskState
  74. assignedTasks map[string]*taskState
  75. recentTasks map[string]*taskState
  76. // Configuration
  77. recentTaskWindowSeconds int
  78. // Synchronization
  79. mutex sync.RWMutex
  80. }
  81. // DestinationPlan represents a planned destination for a volume/shard operation
  82. type DestinationPlan struct {
  83. TargetNode string `json:"target_node"`
  84. TargetDisk uint32 `json:"target_disk"`
  85. TargetRack string `json:"target_rack"`
  86. TargetDC string `json:"target_dc"`
  87. ExpectedSize uint64 `json:"expected_size"`
  88. PlacementScore float64 `json:"placement_score"`
  89. }
  90. // MultiDestinationPlan represents multiple planned destinations for operations like EC
  91. type MultiDestinationPlan struct {
  92. Plans []*DestinationPlan `json:"plans"`
  93. TotalShards int `json:"total_shards"`
  94. SuccessfulRack int `json:"successful_racks"`
  95. SuccessfulDCs int `json:"successful_dcs"`
  96. }
  97. // VolumeReplica represents a replica location with server and disk information
  98. type VolumeReplica struct {
  99. ServerID string `json:"server_id"`
  100. DiskID uint32 `json:"disk_id"`
  101. DataCenter string `json:"data_center"`
  102. Rack string `json:"rack"`
  103. }