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.

97 lines
2.7 KiB

  1. package storage
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  6. "github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
  7. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  8. )
  9. func (s *Store) CollectErasureCodingHeartbeat() *master_pb.Heartbeat {
  10. var ecShardMessages []*master_pb.VolumeEcShardInformationMessage
  11. for _, location := range s.Locations {
  12. location.ecShardsLock.RLock()
  13. for _, ecShards := range location.ecShards {
  14. ecShardMessages = append(ecShardMessages, ecShards.ToVolumeEcShardInformationMessage()...)
  15. }
  16. location.ecShardsLock.RUnlock()
  17. }
  18. return &master_pb.Heartbeat{
  19. EcShards: ecShardMessages,
  20. }
  21. }
  22. func (s *Store) MountEcShards(collection string, vid needle.VolumeId, shardId erasure_coding.ShardId) error {
  23. for _, location := range s.Locations {
  24. if err := location.LoadEcShard(collection, vid, shardId); err == nil {
  25. glog.V(0).Infof("MountEcShards %d.%d", vid, shardId)
  26. var shardBits erasure_coding.ShardBits
  27. s.NewEcShardsChan <- master_pb.VolumeEcShardInformationMessage{
  28. Id: uint32(vid),
  29. Collection: collection,
  30. EcIndexBits: uint32(shardBits.AddShardId(shardId)),
  31. }
  32. return nil
  33. }
  34. }
  35. return fmt.Errorf("MountEcShards %d.%d not found on disk", vid, shardId)
  36. }
  37. func (s *Store) UnmountEcShards(vid needle.VolumeId, shardId erasure_coding.ShardId) error {
  38. ecShard, found := s.findEcShard(vid, shardId)
  39. if !found {
  40. return nil
  41. }
  42. var shardBits erasure_coding.ShardBits
  43. message := master_pb.VolumeEcShardInformationMessage{
  44. Id: uint32(vid),
  45. Collection: ecShard.Collection,
  46. EcIndexBits: uint32(shardBits.AddShardId(shardId)),
  47. }
  48. for _, location := range s.Locations {
  49. if deleted := location.UnloadEcShard(vid, shardId); deleted {
  50. glog.V(0).Infof("UnmountEcShards %d.%d", vid, shardId)
  51. s.DeletedEcShardsChan <- message
  52. return nil
  53. }
  54. }
  55. return fmt.Errorf("UnmountEcShards %d.%d not found on disk", vid, shardId)
  56. }
  57. func (s *Store) findEcShard(vid needle.VolumeId, shardId erasure_coding.ShardId) (*erasure_coding.EcVolumeShard, bool) {
  58. for _, location := range s.Locations {
  59. if v, found := location.FindEcShard(vid, shardId); found {
  60. return v, found
  61. }
  62. }
  63. return nil, false
  64. }
  65. func (s *Store) HasEcShard(vid needle.VolumeId) (erasure_coding.EcVolumeShards, bool) {
  66. for _, location := range s.Locations {
  67. if s, found := location.HasEcShard(vid); found {
  68. return s, true
  69. }
  70. }
  71. return nil, false
  72. }
  73. func (s *Store) ReadEcShardNeedle(vid needle.VolumeId, n *needle.Needle) (int, error) {
  74. for _, location := range s.Locations {
  75. if ecShards, found := location.HasEcShard(vid); found {
  76. return ecShards.ReadEcShardNeedle(n)
  77. }
  78. }
  79. return 0, fmt.Errorf("ec shard %d not found", vid)
  80. }