diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-05-23 22:51:18 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-05-23 22:51:18 -0700 |
| commit | 8a96445f402a240956adf081de3a675e2e41c767 (patch) | |
| tree | 1e1d2fddee9f3d1bab4d966149a8a8d137e2aa76 /weed/topology/data_node_ec.go | |
| parent | 4659d80035430bcbd6f1642311680af0f7a6f215 (diff) | |
| download | seaweedfs-8a96445f402a240956adf081de3a675e2e41c767.tar.xz seaweedfs-8a96445f402a240956adf081de3a675e2e41c767.zip | |
register ec shards to each data node
Diffstat (limited to 'weed/topology/data_node_ec.go')
| -rw-r--r-- | weed/topology/data_node_ec.go | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/weed/topology/data_node_ec.go b/weed/topology/data_node_ec.go index 5206a3b51..ef395dbdb 100644 --- a/weed/topology/data_node_ec.go +++ b/weed/topology/data_node_ec.go @@ -2,6 +2,7 @@ package topology import ( "github.com/chrislusf/seaweedfs/weed/storage/erasure_coding" + "github.com/chrislusf/seaweedfs/weed/storage/needle" ) func (dn *DataNode) GetEcShards() (ret []*erasure_coding.EcVolumeInfo) { @@ -14,7 +15,43 @@ func (dn *DataNode) GetEcShards() (ret []*erasure_coding.EcVolumeInfo) { } func (dn *DataNode) UpdateEcShards(actualShards []*erasure_coding.EcVolumeInfo) (newShards, deletedShards []*erasure_coding.EcVolumeInfo) { - dn.ecShardsLock.Lock() - dn.ecShardsLock.Unlock() + // prepare the new ec shard map + actualEcShardMap := make(map[needle.VolumeId]*erasure_coding.EcVolumeInfo) + for _, ecShards := range actualShards { + actualEcShardMap[ecShards.VolumeId]= ecShards + } + + // found out the newShards and deletedShards + dn.ecShardsLock.RLock() + for vid, ecShards := range dn.ecShards{ + 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) + if len(a.ShardIds())>0 { + newShards = append(newShards, a) + } + d := ecShards.Minus(actualEcShards) + if len(d.ShardIds())>0 { + deletedShards = append(deletedShards, d) + } + } + } + for _, ecShards := range actualShards { + if _, found := dn.ecShards[ecShards.VolumeId]; !found { + newShards = append(newShards, ecShards) + } + } + dn.ecShardsLock.RUnlock() + + if len(newShards)>0 || len(deletedShards)>0{ + // if changed, set to the new ec shard map + dn.ecShardsLock.Lock() + dn.ecShards = actualEcShardMap + dn.ecShardsLock.Unlock() + } + return } |
