storage_impact.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package topology
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/glog"
  4. "github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
  5. )
  6. // CalculateTaskStorageImpact calculates storage impact for different task types
  7. func CalculateTaskStorageImpact(taskType TaskType, volumeSize int64) (sourceChange, targetChange StorageSlotChange) {
  8. switch taskType {
  9. case TaskTypeErasureCoding:
  10. // EC task: distributes shards to MULTIPLE targets, source reserves with zero impact
  11. // Source reserves capacity but with zero StorageSlotChange (no actual capacity consumption during planning)
  12. // WARNING: EC has multiple targets! Use AddPendingTask with multiple destinations for proper multi-target handling
  13. // This simplified function returns zero impact; real EC requires specialized multi-destination calculation
  14. return StorageSlotChange{VolumeSlots: 0, ShardSlots: 0}, StorageSlotChange{VolumeSlots: 0, ShardSlots: 0}
  15. case TaskTypeBalance:
  16. // Balance task: moves volume from source to target
  17. // Source loses 1 volume, target gains 1 volume
  18. return StorageSlotChange{VolumeSlots: -1, ShardSlots: 0}, StorageSlotChange{VolumeSlots: 1, ShardSlots: 0}
  19. case TaskTypeVacuum:
  20. // Vacuum task: frees space by removing deleted entries, no slot change
  21. return StorageSlotChange{VolumeSlots: 0, ShardSlots: 0}, StorageSlotChange{VolumeSlots: 0, ShardSlots: 0}
  22. case TaskTypeReplication:
  23. // Replication task: creates new replica on target
  24. return StorageSlotChange{VolumeSlots: 0, ShardSlots: 0}, StorageSlotChange{VolumeSlots: 1, ShardSlots: 0}
  25. default:
  26. // Unknown task type, assume minimal impact
  27. glog.Warningf("unhandled task type %s in CalculateTaskStorageImpact, assuming default impact", taskType)
  28. return StorageSlotChange{VolumeSlots: 0, ShardSlots: 0}, StorageSlotChange{VolumeSlots: 1, ShardSlots: 0}
  29. }
  30. }
  31. // CalculateECShardStorageImpact calculates storage impact for EC shards specifically
  32. func CalculateECShardStorageImpact(shardCount int32, expectedShardSize int64) StorageSlotChange {
  33. // EC shards are typically much smaller than full volumes
  34. // Use shard-level tracking for granular capacity planning
  35. return StorageSlotChange{VolumeSlots: 0, ShardSlots: shardCount}
  36. }
  37. // CalculateECShardCleanupImpact calculates storage impact for cleaning up existing EC shards
  38. func CalculateECShardCleanupImpact(originalVolumeSize int64) StorageSlotChange {
  39. // Cleaning up existing EC shards frees shard slots
  40. // Use the actual EC configuration constants for accurate shard count
  41. return StorageSlotChange{VolumeSlots: 0, ShardSlots: -int32(erasure_coding.TotalShardsCount)} // Negative = freed capacity
  42. }