mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-21 10:07:24 +08:00
volume: automatically detect max volume count
This commit is contained in:
@@ -275,3 +275,19 @@ func (l *DiskLocation) LocateVolume(vid needle.VolumeId) (os.FileInfo, bool) {
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (l *DiskLocation) UnUsedSpace(volumeSizeLimit uint64) (unUsedSpace uint64) {
|
||||
|
||||
l.volumesLock.RLock()
|
||||
defer l.volumesLock.RUnlock()
|
||||
|
||||
for _, vol := range l.volumes {
|
||||
if vol.IsReadOnly() {
|
||||
continue
|
||||
}
|
||||
datSize, idxSize, _ := vol.FileStat()
|
||||
unUsedSpace += volumeSizeLimit - (datSize + idxSize)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@@ -183,3 +183,10 @@ func (l *DiskLocation) unmountEcVolumeByCollection(collectionName string) map[ne
|
||||
}
|
||||
return deltaVols
|
||||
}
|
||||
|
||||
func (l *DiskLocation) EcVolumesLen() int {
|
||||
l.ecVolumesLock.RLock()
|
||||
defer l.ecVolumesLock.RUnlock()
|
||||
|
||||
return len(l.ecVolumes)
|
||||
}
|
||||
|
@@ -152,6 +152,13 @@ func (ev *EcVolume) ShardSize() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (ev *EcVolume) Size() (size int64) {
|
||||
for _, shard := range ev.Shards {
|
||||
size += shard.Size()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ev *EcVolume) CreatedAt() time.Time {
|
||||
return ev.ecxCreatedAt
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/chrislusf/seaweedfs/weed/pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/stats"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
||||
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
||||
@@ -99,6 +100,9 @@ func (s *Store) FindFreeLocation() (ret *DiskLocation) {
|
||||
max := 0
|
||||
for _, location := range s.Locations {
|
||||
currentFreeCount := location.MaxVolumeCount - location.VolumesLen()
|
||||
currentFreeCount *= erasure_coding.DataShardsCount
|
||||
currentFreeCount -= location.EcVolumesLen()
|
||||
currentFreeCount /= erasure_coding.DataShardsCount
|
||||
if currentFreeCount > max {
|
||||
max = currentFreeCount
|
||||
ret = location
|
||||
@@ -382,3 +386,24 @@ func (s *Store) SetVolumeSizeLimit(x uint64) {
|
||||
func (s *Store) GetVolumeSizeLimit() uint64 {
|
||||
return atomic.LoadUint64(&s.volumeSizeLimit)
|
||||
}
|
||||
|
||||
func (s *Store) MaybeAdjustVolumeMax() (hasChanges bool) {
|
||||
volumeSizeLimit := s.GetVolumeSizeLimit()
|
||||
for _, diskLocation := range s.Locations {
|
||||
if diskLocation.MaxVolumeCount == 0 {
|
||||
diskStatus := stats.NewDiskStatus(diskLocation.Directory)
|
||||
unusedSpace := diskLocation.UnUsedSpace(volumeSizeLimit)
|
||||
unclaimedSpaces := int64(diskStatus.Free) - int64(unusedSpace)
|
||||
volCount := diskLocation.VolumesLen()
|
||||
maxVolumeCount := volCount
|
||||
if unclaimedSpaces > int64(volumeSizeLimit) {
|
||||
maxVolumeCount += int(uint64(unclaimedSpaces)/volumeSizeLimit) - 1
|
||||
}
|
||||
diskLocation.MaxVolumeCount = maxVolumeCount
|
||||
glog.V(0).Infof("disk %s max %d unclaimedSpace:%dMB, unused:%dMB volumeSizeLimit:%d/MB",
|
||||
diskLocation.Directory, maxVolumeCount, unclaimedSpaces/1024/1024, unusedSpace/1024/1024, volumeSizeLimit/1024/1024)
|
||||
hasChanges = true
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user