diff options
| author | Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> | 2024-07-16 20:03:40 +0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-16 08:03:40 -0700 |
| commit | 67edf1d01413f330d6983125b94e5c3d40a845f2 (patch) | |
| tree | 03d337c508e8d66ffaa92c2916f5970cc6c5d53c /weed/server/master_grpc_server_volume.go | |
| parent | ce61a66b651f83b851e85d68e91f62e0aea00ec7 (diff) | |
| download | seaweedfs-67edf1d01413f330d6983125b94e5c3d40a845f2.tar.xz seaweedfs-67edf1d01413f330d6983125b94e5c3d40a845f2.zip | |
[master] Do Automatic Volume Grow in background (#5781)
* Do Automatic Volume Grow in backgound
* pass lastGrowCount to master
* fix build
* fix count to uint64
Diffstat (limited to 'weed/server/master_grpc_server_volume.go')
| -rw-r--r-- | weed/server/master_grpc_server_volume.go | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/weed/server/master_grpc_server_volume.go b/weed/server/master_grpc_server_volume.go index afe062a2d..f48326459 100644 --- a/weed/server/master_grpc_server_volume.go +++ b/weed/server/master_grpc_server_volume.go @@ -3,6 +3,8 @@ package weed_server import ( "context" "fmt" + "github.com/seaweedfs/seaweedfs/weed/topology" + "math/rand" "reflect" "strings" "sync" @@ -18,8 +20,39 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/types" ) +func (ms *MasterServer) DoAutomaticVolumeGrow(req *topology.VolumeGrowRequest) { + glog.V(1).Infoln("starting automatic volume grow") + start := time.Now() + newVidLocations, err := ms.vg.AutomaticGrowByType(req.Option, ms.grpcDialOption, ms.Topo, req.Count) + glog.V(1).Infoln("finished automatic volume grow, cost ", time.Now().Sub(start)) + if err != nil { + glog.V(1).Infof("automatic volume grow failed: %+v", err) + return + } + for _, newVidLocation := range newVidLocations { + ms.broadcastToClients(&master_pb.KeepConnectedResponse{VolumeLocation: newVidLocation}) + } +} + func (ms *MasterServer) ProcessGrowRequest() { go func() { + for { + time.Sleep(14*time.Minute + time.Duration(120*rand.Float32())*time.Second) + if !ms.Topo.IsLeader() { + continue + } + for _, vl := range ms.Topo.ListVolumeLyauts() { + if !vl.HasGrowRequest() && vl.ShouldGrowVolumes(&topology.VolumeGrowOption{}) { + vl.AddGrowRequest() + ms.volumeGrowthRequestChan <- &topology.VolumeGrowRequest{ + Option: vl.ToGrowOption(), + Count: vl.GetLastGrowCount(), + } + } + } + } + }() + go func() { filter := sync.Map{} for { req, ok := <-ms.volumeGrowthRequestChan @@ -50,23 +83,11 @@ func (ms *MasterServer) ProcessGrowRequest() { if !found && vl.ShouldGrowVolumes(option) { filter.Store(req, nil) // we have lock called inside vg - go func() { - glog.V(1).Infoln("starting automatic volume grow") - start := time.Now() - newVidLocations, err := ms.vg.AutomaticGrowByType(req.Option, ms.grpcDialOption, ms.Topo, req.Count) - glog.V(1).Infoln("finished automatic volume grow, cost ", time.Now().Sub(start)) - if err == nil { - for _, newVidLocation := range newVidLocations { - ms.broadcastToClients(&master_pb.KeepConnectedResponse{VolumeLocation: newVidLocation}) - } - } else { - glog.V(1).Infof("automatic volume grow failed: %+v", err) - } + go func(req *topology.VolumeGrowRequest, vl *topology.VolumeLayout) { + ms.DoAutomaticVolumeGrow(req) vl.DoneGrowRequest() - filter.Delete(req) - }() - + }(req, vl) } else { glog.V(4).Infoln("discard volume grow request") time.Sleep(time.Millisecond * 211) |
