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.

57 lines
1.6 KiB

  1. package topology
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
  4. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  5. )
  6. func (dn *DataNode) GetEcShards() (ret []*erasure_coding.EcVolumeInfo) {
  7. dn.RLock()
  8. for _, ecVolumeInfo := range dn.ecShards {
  9. ret = append(ret, ecVolumeInfo)
  10. }
  11. dn.RUnlock()
  12. return ret
  13. }
  14. func (dn *DataNode) UpdateEcShards(actualShards []*erasure_coding.EcVolumeInfo) (newShards, deletedShards []*erasure_coding.EcVolumeInfo) {
  15. // prepare the new ec shard map
  16. actualEcShardMap := make(map[needle.VolumeId]*erasure_coding.EcVolumeInfo)
  17. for _, ecShards := range actualShards {
  18. actualEcShardMap[ecShards.VolumeId] = ecShards
  19. }
  20. // found out the newShards and deletedShards
  21. dn.ecShardsLock.RLock()
  22. for vid, ecShards := range dn.ecShards {
  23. if actualEcShards, ok := actualEcShardMap[vid]; !ok {
  24. // dn registered ec shards not found in the new set of ec shards
  25. deletedShards = append(deletedShards, ecShards)
  26. } else {
  27. // found, but maybe the actual shard could be missing
  28. a := actualEcShards.Minus(ecShards)
  29. if len(a.ShardIds()) > 0 {
  30. newShards = append(newShards, a)
  31. }
  32. d := ecShards.Minus(actualEcShards)
  33. if len(d.ShardIds()) > 0 {
  34. deletedShards = append(deletedShards, d)
  35. }
  36. }
  37. }
  38. for _, ecShards := range actualShards {
  39. if _, found := dn.ecShards[ecShards.VolumeId]; !found {
  40. newShards = append(newShards, ecShards)
  41. }
  42. }
  43. dn.ecShardsLock.RUnlock()
  44. if len(newShards) > 0 || len(deletedShards) > 0 {
  45. // if changed, set to the new ec shard map
  46. dn.ecShardsLock.Lock()
  47. dn.ecShards = actualEcShardMap
  48. dn.ecShardsLock.Unlock()
  49. }
  50. return
  51. }