seaweedfs/weed/topology/data_node_ec.go

58 lines
1.6 KiB
Go
Raw Normal View History

package topology
import (
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
2019-05-24 05:51:18 +00:00
"github.com/chrislusf/seaweedfs/weed/storage/needle"
)
func (dn *DataNode) GetEcShards() (ret []*erasure_coding.EcVolumeInfo) {
dn.RLock()
for _, ecVolumeInfo := range dn.ecShards {
ret = append(ret, ecVolumeInfo)
}
dn.RUnlock()
return ret
}
func (dn *DataNode) UpdateEcShards(actualShards []*erasure_coding.EcVolumeInfo) (newShards, deletedShards []*erasure_coding.EcVolumeInfo) {
2019-05-24 05:51:18 +00:00
// prepare the new ec shard map
actualEcShardMap := make(map[needle.VolumeId]*erasure_coding.EcVolumeInfo)
for _, ecShards := range actualShards {
2019-05-24 06:34:29 +00:00
actualEcShardMap[ecShards.VolumeId] = ecShards
2019-05-24 05:51:18 +00:00
}
// found out the newShards and deletedShards
dn.ecShardsLock.RLock()
2019-05-24 06:34:29 +00:00
for vid, ecShards := range dn.ecShards {
2019-05-24 05:51:18 +00:00
if actualEcShards, ok := actualEcShardMap[vid]; !ok {
// dn registered ec shards not found in the new set of ec shards
deletedShards = append(deletedShards, ecShards)
} else {
// found, but maybe the actual shard could be missing
a := actualEcShards.Minus(ecShards)
2019-05-25 09:02:44 +00:00
if a.ShardIdCount() > 0 {
2019-05-24 05:51:18 +00:00
newShards = append(newShards, a)
}
d := ecShards.Minus(actualEcShards)
2019-05-25 09:02:44 +00:00
if d.ShardIdCount() > 0 {
2019-05-24 05:51:18 +00:00
deletedShards = append(deletedShards, d)
}
}
}
for _, ecShards := range actualShards {
if _, found := dn.ecShards[ecShards.VolumeId]; !found {
newShards = append(newShards, ecShards)
}
}
dn.ecShardsLock.RUnlock()
2019-05-24 06:34:29 +00:00
if len(newShards) > 0 || len(deletedShards) > 0 {
2019-05-24 05:51:18 +00:00
// if changed, set to the new ec shard map
dn.ecShardsLock.Lock()
dn.ecShards = actualEcShardMap
dn.ecShardsLock.Unlock()
}
return
}