From 0dafcf1f5a3c868a768cab99af3bea45e6cfe553 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 3 Nov 2020 14:43:17 -0800 Subject: [PATCH] volume: detect max volume count changes based on disk usage fix https://github.com/chrislusf/seaweedfs/issues/1594 --- weed/server/volume_grpc_client_to_master.go | 1 + weed/storage/disk_location.go | 13 +++++++------ weed/storage/store.go | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/weed/server/volume_grpc_client_to_master.go b/weed/server/volume_grpc_client_to_master.go index 84467ec1c..2f594fa2b 100644 --- a/weed/server/volume_grpc_client_to_master.go +++ b/weed/server/volume_grpc_client_to_master.go @@ -203,6 +203,7 @@ func (vs *VolumeServer) doHeartbeat(masterNode, masterGrpcAddress string, grpcDi } case <-volumeTickChan: 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 { glog.V(0).Infof("Volume Server Failed to talk with master %s: %v", masterNode, err) return "", err diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index 1f58c9977..775ebf092 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -17,11 +17,12 @@ import ( ) type DiskLocation struct { - Directory string - MaxVolumeCount int - MinFreeSpacePercent float32 - volumes map[needle.VolumeId]*Volume - volumesLock sync.RWMutex + Directory string + MaxVolumeCount int + OriginalMaxVolumeCount int + MinFreeSpacePercent float32 + volumes map[needle.VolumeId]*Volume + volumesLock sync.RWMutex // erasure coding ecVolumes map[needle.VolumeId]*erasure_coding.EcVolume @@ -31,7 +32,7 @@ type DiskLocation struct { } 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.ecVolumes = make(map[needle.VolumeId]*erasure_coding.EcVolume) go location.CheckDiskSpace() diff --git a/weed/storage/store.go b/weed/storage/store.go index 946ba0df1..38f167cef 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -461,7 +461,8 @@ func (s *Store) GetVolumeSizeLimit() uint64 { func (s *Store) MaybeAdjustVolumeMax() (hasChanges bool) { volumeSizeLimit := s.GetVolumeSizeLimit() for _, diskLocation := range s.Locations { - if diskLocation.MaxVolumeCount == 0 { + if diskLocation.OriginalMaxVolumeCount == 0 { + currentMaxVolumeCount := diskLocation.MaxVolumeCount diskStatus := stats.NewDiskStatus(diskLocation.Directory) unusedSpace := diskLocation.UnUsedSpace(volumeSizeLimit) unclaimedSpaces := int64(diskStatus.Free) - int64(unusedSpace) @@ -473,7 +474,7 @@ func (s *Store) MaybeAdjustVolumeMax() (hasChanges bool) { diskLocation.MaxVolumeCount = maxVolumeCount 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) - hasChanges = true + hasChanges = hasChanges || currentMaxVolumeCount != diskLocation.MaxVolumeCount } } return