aboutsummaryrefslogtreecommitdiff
path: root/weed/topology/data_node_ec.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2019-06-04 23:41:56 -0700
committerChris Lu <chris.lu@gmail.com>2019-06-04 23:41:56 -0700
commiteaa76f11b7911af7c1faebddcccd4af2404122d6 (patch)
tree0d80cd90faefa5ccab536eefc630615a26927084 /weed/topology/data_node_ec.go
parentca8a2bb5345aec1d15bf087d66028292d567de87 (diff)
downloadseaweedfs-eaa76f11b7911af7c1faebddcccd4af2404122d6.tar.xz
seaweedfs-eaa76f11b7911af7c1faebddcccd4af2404122d6.zip
free volume slots factor in ec shard counts
Diffstat (limited to 'weed/topology/data_node_ec.go')
-rw-r--r--weed/topology/data_node_ec.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/weed/topology/data_node_ec.go b/weed/topology/data_node_ec.go
index a0e3a699f..3df9394da 100644
--- a/weed/topology/data_node_ec.go
+++ b/weed/topology/data_node_ec.go
@@ -14,17 +14,6 @@ func (dn *DataNode) GetEcShards() (ret []*erasure_coding.EcVolumeInfo) {
return ret
}
-func (dn *DataNode) GetEcShardsCount() (count int) {
- dn.RLock()
- defer dn.RUnlock()
-
- for _, ecVolumeInfo := range dn.ecShards {
- count += ecVolumeInfo.ShardBits.ShardIdCount()
- }
-
- return count
-}
-
func (dn *DataNode) UpdateEcShards(actualShards []*erasure_coding.EcVolumeInfo) (newShards, deletedShards []*erasure_coding.EcVolumeInfo) {
// prepare the new ec shard map
actualEcShardMap := make(map[needle.VolumeId]*erasure_coding.EcVolumeInfo)
@@ -61,6 +50,7 @@ func (dn *DataNode) UpdateEcShards(actualShards []*erasure_coding.EcVolumeInfo)
// if changed, set to the new ec shard map
dn.ecShardsLock.Lock()
dn.ecShards = actualEcShardMap
+ dn.UpAdjustEcShardCountDelta(int64(len(newShards) - len(deletedShards)))
dn.ecShardsLock.Unlock()
}
@@ -83,12 +73,18 @@ func (dn *DataNode) AddOrUpdateEcShard(s *erasure_coding.EcVolumeInfo) {
dn.ecShardsLock.Lock()
defer dn.ecShardsLock.Unlock()
+ delta := 0
if existing, ok := dn.ecShards[s.VolumeId]; !ok {
dn.ecShards[s.VolumeId] = s
+ delta = s.ShardBits.ShardIdCount()
} else {
+ oldCount := existing.ShardBits.ShardIdCount()
existing.ShardBits = existing.ShardBits.Plus(s.ShardBits)
+ delta = existing.ShardBits.ShardIdCount() - oldCount
}
+ dn.UpAdjustEcShardCountDelta(int64(delta))
+
}
func (dn *DataNode) DeleteEcShard(s *erasure_coding.EcVolumeInfo) {
@@ -96,7 +92,10 @@ func (dn *DataNode) DeleteEcShard(s *erasure_coding.EcVolumeInfo) {
defer dn.ecShardsLock.Unlock()
if existing, ok := dn.ecShards[s.VolumeId]; ok {
+ oldCount := existing.ShardBits.ShardIdCount()
existing.ShardBits = existing.ShardBits.Minus(s.ShardBits)
+ delta := existing.ShardBits.ShardIdCount() - oldCount
+ dn.UpAdjustEcShardCountDelta(int64(delta))
if existing.ShardBits.ShardIdCount() == 0 {
delete(dn.ecShards, s.VolumeId)
}