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.

87 lines
1.9 KiB

  1. package topology
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
  4. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  5. "github.com/seaweedfs/seaweedfs/weed/storage/types"
  6. )
  7. func (d *Disk) GetEcShards() (ret []*erasure_coding.EcVolumeInfo) {
  8. d.RLock()
  9. for _, ecVolumeInfo := range d.ecShards {
  10. ret = append(ret, ecVolumeInfo)
  11. }
  12. d.RUnlock()
  13. return ret
  14. }
  15. func (d *Disk) AddOrUpdateEcShard(s *erasure_coding.EcVolumeInfo) {
  16. d.ecShardsLock.Lock()
  17. defer d.ecShardsLock.Unlock()
  18. delta := 0
  19. if existing, ok := d.ecShards[s.VolumeId]; !ok {
  20. d.ecShards[s.VolumeId] = s
  21. delta = s.ShardBits.ShardIdCount()
  22. } else {
  23. oldCount := existing.ShardBits.ShardIdCount()
  24. existing.ShardBits = existing.ShardBits.Plus(s.ShardBits)
  25. delta = existing.ShardBits.ShardIdCount() - oldCount
  26. }
  27. if delta == 0 {
  28. return
  29. }
  30. d.UpAdjustDiskUsageDelta(types.ToDiskType(string(d.Id())), &DiskUsageCounts{
  31. ecShardCount: int64(delta),
  32. })
  33. }
  34. func (d *Disk) DeleteEcShard(s *erasure_coding.EcVolumeInfo) {
  35. d.ecShardsLock.Lock()
  36. defer d.ecShardsLock.Unlock()
  37. if existing, ok := d.ecShards[s.VolumeId]; ok {
  38. oldCount := existing.ShardBits.ShardIdCount()
  39. existing.ShardBits = existing.ShardBits.Minus(s.ShardBits)
  40. delta := existing.ShardBits.ShardIdCount() - oldCount
  41. if delta != 0 {
  42. d.UpAdjustDiskUsageDelta(types.ToDiskType(string(d.Id())), &DiskUsageCounts{
  43. ecShardCount: int64(delta),
  44. })
  45. }
  46. if existing.ShardBits.ShardIdCount() == 0 {
  47. delete(d.ecShards, s.VolumeId)
  48. }
  49. }
  50. }
  51. func (d *Disk) HasVolumesById(id needle.VolumeId) (hasVolumeId bool) {
  52. // check whether normal volumes has this volume id
  53. d.RLock()
  54. _, ok := d.volumes[id]
  55. if ok {
  56. hasVolumeId = true
  57. }
  58. d.RUnlock()
  59. if hasVolumeId {
  60. return
  61. }
  62. // check whether ec shards has this volume id
  63. d.ecShardsLock.RLock()
  64. _, ok = d.ecShards[id]
  65. if ok {
  66. hasVolumeId = true
  67. }
  68. d.ecShardsLock.RUnlock()
  69. return
  70. }