From 050efe6c0846ea94bec0de2709b922da62b80d12 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 11 Jan 2024 08:19:09 -0800 Subject: [PATCH] factor in existing ec volume count when estimating max volume count related to https://github.com/seaweedfs/seaweedfs/issues/5191 --- weed/storage/disk_location_ec.go | 8 ++++++-- weed/storage/store.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/weed/storage/disk_location_ec.go b/weed/storage/disk_location_ec.go index 6d681d2c2..4050a7930 100644 --- a/weed/storage/disk_location_ec.go +++ b/weed/storage/disk_location_ec.go @@ -218,9 +218,13 @@ func (l *DiskLocation) unmountEcVolumeByCollection(collectionName string) map[ne return deltaVols } -func (l *DiskLocation) EcVolumesLen() int { +func (l *DiskLocation) EcShardCount() int { l.ecVolumesLock.RLock() defer l.ecVolumesLock.RUnlock() - return len(l.ecVolumes) + shardCount := 0 + for _, ecVolume := range l.ecVolumes { + shardCount += len(ecVolume.Shards) + } + return shardCount } diff --git a/weed/storage/store.go b/weed/storage/store.go index 6b4467abc..d290909f1 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -149,7 +149,7 @@ func (s *Store) FindFreeLocation(diskType DiskType) (ret *DiskLocation) { } currentFreeCount := location.MaxVolumeCount - int32(location.VolumesLen()) currentFreeCount *= erasure_coding.DataShardsCount - currentFreeCount -= int32(location.EcVolumesLen()) + currentFreeCount -= int32(location.EcShardCount()) currentFreeCount /= erasure_coding.DataShardsCount if currentFreeCount > max { max = currentFreeCount