volume: detect max volume count changes based on disk usage

fix https://github.com/chrislusf/seaweedfs/issues/1594
This commit is contained in:
Chris Lu 2020-11-03 14:43:17 -08:00
parent 06ee199ef3
commit 0dafcf1f5a
3 changed files with 11 additions and 8 deletions

View file

@ -203,6 +203,7 @@ func (vs *VolumeServer) doHeartbeat(masterNode, masterGrpcAddress string, grpcDi
} }
case <-volumeTickChan: case <-volumeTickChan:
glog.V(4).Infof("volume server %s:%d heartbeat", vs.store.Ip, vs.store.Port) glog.V(4).Infof("volume server %s:%d heartbeat", vs.store.Ip, vs.store.Port)
vs.store.MaybeAdjustVolumeMax()
if err = stream.Send(vs.store.CollectHeartbeat()); err != nil { if err = stream.Send(vs.store.CollectHeartbeat()); err != nil {
glog.V(0).Infof("Volume Server Failed to talk with master %s: %v", masterNode, err) glog.V(0).Infof("Volume Server Failed to talk with master %s: %v", masterNode, err)
return "", err return "", err

View file

@ -17,11 +17,12 @@ import (
) )
type DiskLocation struct { type DiskLocation struct {
Directory string Directory string
MaxVolumeCount int MaxVolumeCount int
MinFreeSpacePercent float32 OriginalMaxVolumeCount int
volumes map[needle.VolumeId]*Volume MinFreeSpacePercent float32
volumesLock sync.RWMutex volumes map[needle.VolumeId]*Volume
volumesLock sync.RWMutex
// erasure coding // erasure coding
ecVolumes map[needle.VolumeId]*erasure_coding.EcVolume ecVolumes map[needle.VolumeId]*erasure_coding.EcVolume
@ -31,7 +32,7 @@ type DiskLocation struct {
} }
func NewDiskLocation(dir string, maxVolumeCount int, minFreeSpacePercent float32) *DiskLocation { func NewDiskLocation(dir string, maxVolumeCount int, minFreeSpacePercent float32) *DiskLocation {
location := &DiskLocation{Directory: dir, MaxVolumeCount: maxVolumeCount, MinFreeSpacePercent: minFreeSpacePercent} location := &DiskLocation{Directory: dir, MaxVolumeCount: maxVolumeCount, OriginalMaxVolumeCount: maxVolumeCount, MinFreeSpacePercent: minFreeSpacePercent}
location.volumes = make(map[needle.VolumeId]*Volume) location.volumes = make(map[needle.VolumeId]*Volume)
location.ecVolumes = make(map[needle.VolumeId]*erasure_coding.EcVolume) location.ecVolumes = make(map[needle.VolumeId]*erasure_coding.EcVolume)
go location.CheckDiskSpace() go location.CheckDiskSpace()

View file

@ -461,7 +461,8 @@ func (s *Store) GetVolumeSizeLimit() uint64 {
func (s *Store) MaybeAdjustVolumeMax() (hasChanges bool) { func (s *Store) MaybeAdjustVolumeMax() (hasChanges bool) {
volumeSizeLimit := s.GetVolumeSizeLimit() volumeSizeLimit := s.GetVolumeSizeLimit()
for _, diskLocation := range s.Locations { for _, diskLocation := range s.Locations {
if diskLocation.MaxVolumeCount == 0 { if diskLocation.OriginalMaxVolumeCount == 0 {
currentMaxVolumeCount := diskLocation.MaxVolumeCount
diskStatus := stats.NewDiskStatus(diskLocation.Directory) diskStatus := stats.NewDiskStatus(diskLocation.Directory)
unusedSpace := diskLocation.UnUsedSpace(volumeSizeLimit) unusedSpace := diskLocation.UnUsedSpace(volumeSizeLimit)
unclaimedSpaces := int64(diskStatus.Free) - int64(unusedSpace) unclaimedSpaces := int64(diskStatus.Free) - int64(unusedSpace)
@ -473,7 +474,7 @@ func (s *Store) MaybeAdjustVolumeMax() (hasChanges bool) {
diskLocation.MaxVolumeCount = maxVolumeCount diskLocation.MaxVolumeCount = maxVolumeCount
glog.V(0).Infof("disk %s max %d unclaimedSpace:%dMB, unused:%dMB volumeSizeLimit:%dMB", glog.V(0).Infof("disk %s max %d unclaimedSpace:%dMB, unused:%dMB volumeSizeLimit:%dMB",
diskLocation.Directory, maxVolumeCount, unclaimedSpaces/1024/1024, unusedSpace/1024/1024, volumeSizeLimit/1024/1024) diskLocation.Directory, maxVolumeCount, unclaimedSpaces/1024/1024, unusedSpace/1024/1024, volumeSizeLimit/1024/1024)
hasChanges = true hasChanges = hasChanges || currentMaxVolumeCount != diskLocation.MaxVolumeCount
} }
} }
return return