diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-05-26 00:21:17 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-05-26 00:21:17 -0700 |
| commit | af67d99ca4aae35b3732654dda52aaa348a75fd9 (patch) | |
| tree | 0366e98fdccf1ce841bb4ecc367f0b9ef43e9c74 /weed/topology/data_node_ec.go | |
| parent | db94a41f9e28e620b7527d9cca51f9a052a81184 (diff) | |
| download | seaweedfs-af67d99ca4aae35b3732654dda52aaa348a75fd9.tar.xz seaweedfs-af67d99ca4aae35b3732654dda52aaa348a75fd9.zip | |
incrementally update master ec shards state
Diffstat (limited to 'weed/topology/data_node_ec.go')
| -rw-r--r-- | weed/topology/data_node_ec.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/weed/topology/data_node_ec.go b/weed/topology/data_node_ec.go index 63c8f2127..95635331b 100644 --- a/weed/topology/data_node_ec.go +++ b/weed/topology/data_node_ec.go @@ -55,3 +55,40 @@ func (dn *DataNode) UpdateEcShards(actualShards []*erasure_coding.EcVolumeInfo) return } + +func (dn *DataNode) DeltaUpdateEcShards(newShards, deletedShards []*erasure_coding.EcVolumeInfo) { + + for _, newShard := range newShards { + dn.AddOrUpdateEcShard(newShard) + } + + for _, deletedShard := range deletedShards { + dn.DeleteEcShard(deletedShard) + } + +} + +func (dn *DataNode) AddOrUpdateEcShard(s *erasure_coding.EcVolumeInfo) { + dn.ecShardsLock.Lock() + defer dn.ecShardsLock.Unlock() + + if existing, ok := dn.ecShards[s.VolumeId]; !ok { + dn.ecShards[s.VolumeId] = s + } else { + existing.ShardBits = existing.ShardBits.Plus(s.ShardBits) + } + +} + +func (dn *DataNode) DeleteEcShard(s *erasure_coding.EcVolumeInfo) { + dn.ecShardsLock.Lock() + defer dn.ecShardsLock.Unlock() + + if existing, ok := dn.ecShards[s.VolumeId]; ok { + existing.ShardBits = existing.ShardBits.Minus(s.ShardBits) + if existing.ShardBits.ShardIdCount() == 0 { + delete(dn.ecShards, s.VolumeId) + } + } + +} |
