2019-05-22 13:41:20 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
2019-05-26 14:23:19 +08:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2019-05-22 13:41:20 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2019-05-26 14:23:19 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
2019-05-22 13:41:20 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Store) CollectErasureCodingHeartbeat() *master_pb.Heartbeat {
|
|
|
|
var ecShardMessages []*master_pb.VolumeEcShardInformationMessage
|
|
|
|
for _, location := range s.Locations {
|
|
|
|
location.ecShardsLock.RLock()
|
|
|
|
for _, ecShards := range location.ecShards {
|
2019-05-25 04:28:44 +08:00
|
|
|
ecShardMessages = append(ecShardMessages, ecShards.ToVolumeEcShardInformationMessage()...)
|
2019-05-22 13:41:20 +08:00
|
|
|
}
|
|
|
|
location.ecShardsLock.RUnlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
return &master_pb.Heartbeat{
|
|
|
|
EcShards: ecShardMessages,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-05-26 14:23:19 +08:00
|
|
|
|
|
|
|
func (s *Store) MountEcShards(collection string, vid needle.VolumeId, shardId erasure_coding.ShardId) error {
|
|
|
|
for _, location := range s.Locations {
|
|
|
|
if err := location.LoadEcShard(collection, vid, shardId); err == nil {
|
|
|
|
glog.V(0).Infof("MountEcShards %d.%d", vid, shardId)
|
|
|
|
|
|
|
|
var shardBits erasure_coding.ShardBits
|
|
|
|
|
|
|
|
s.NewEcShardsChan <- master_pb.VolumeEcShardInformationMessage{
|
2019-05-27 16:29:46 +08:00
|
|
|
Id: uint32(vid),
|
|
|
|
Collection: collection,
|
|
|
|
EcIndexBits: uint32(shardBits.AddShardId(shardId)),
|
2019-05-26 14:23:19 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("MountEcShards %d.%d not found on disk", vid, shardId)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) UnmountEcShards(vid needle.VolumeId, shardId erasure_coding.ShardId) error {
|
|
|
|
|
|
|
|
ecShard, found := s.findEcShard(vid, shardId)
|
|
|
|
if !found {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var shardBits erasure_coding.ShardBits
|
|
|
|
message := master_pb.VolumeEcShardInformationMessage{
|
2019-05-27 16:29:46 +08:00
|
|
|
Id: uint32(vid),
|
|
|
|
Collection: ecShard.Collection,
|
|
|
|
EcIndexBits: uint32(shardBits.AddShardId(shardId)),
|
2019-05-26 14:23:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, location := range s.Locations {
|
|
|
|
if deleted := location.UnloadEcShard(vid, shardId); deleted {
|
|
|
|
glog.V(0).Infof("UnmountEcShards %d.%d", vid, shardId)
|
|
|
|
s.DeletedEcShardsChan <- message
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("UnmountEcShards %d.%d not found on disk", vid, shardId)
|
|
|
|
}
|
|
|
|
|
2019-05-27 16:29:46 +08:00
|
|
|
func (s *Store) findEcShard(vid needle.VolumeId, shardId erasure_coding.ShardId) (*erasure_coding.EcVolumeShard, bool) {
|
2019-05-26 14:23:19 +08:00
|
|
|
for _, location := range s.Locations {
|
|
|
|
if v, found := location.FindEcShard(vid, shardId); found {
|
|
|
|
return v, found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
2019-05-27 16:29:46 +08:00
|
|
|
|
|
|
|
func (s *Store) HasEcShard(vid needle.VolumeId) (erasure_coding.EcVolumeShards, bool) {
|
|
|
|
for _, location := range s.Locations {
|
|
|
|
if s, found := location.HasEcShard(vid); found {
|
|
|
|
return s, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) ReadEcShardNeedle(vid needle.VolumeId, n *needle.Needle) (int, error) {
|
|
|
|
for _, location := range s.Locations {
|
|
|
|
if ecShards, found := location.HasEcShard(vid); found {
|
|
|
|
return ecShards.ReadEcShardNeedle(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0, fmt.Errorf("ec shard %d not found", vid)
|
|
|
|
}
|