seaweedfs/weed/topology/topology_event_handling.go

94 lines
2.8 KiB
Go
Raw Normal View History

2012-09-19 23:48:04 +00:00
package topology
import (
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
2019-02-18 20:11:52 +00:00
"google.golang.org/grpc"
2012-09-19 23:48:04 +00:00
"math/rand"
"time"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/storage"
2012-09-19 23:48:04 +00:00
)
2021-05-06 10:46:14 +00:00
func (t *Topology) StartRefreshWritableVolumes(grpcDialOption grpc.DialOption, garbageThreshold float64, growThreshold float64, preallocate int64) {
2012-09-19 23:48:04 +00:00
go func() {
for {
if t.IsLeader() {
2014-02-10 07:37:29 +00:00
freshThreshHold := time.Now().Unix() - 3*t.pulse //3 times of sleep interval
2021-05-06 10:46:14 +00:00
t.CollectDeadNodeAndFullVolumes(freshThreshHold, t.volumeSizeLimit, growThreshold)
2014-02-10 07:37:29 +00:00
}
2012-09-19 23:48:04 +00:00
time.Sleep(time.Duration(float32(t.pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
}
}()
2018-10-15 06:12:43 +00:00
go func(garbageThreshold float64) {
2012-11-24 01:03:27 +00:00
c := time.Tick(15 * time.Minute)
for _ = range c {
if t.IsLeader() {
t.Vacuum(grpcDialOption, garbageThreshold, 0, "", preallocate)
2014-02-10 07:37:29 +00:00
}
2012-11-24 01:03:27 +00:00
}
}(garbageThreshold)
2012-09-19 23:48:04 +00:00
go func() {
for {
select {
2021-05-06 10:46:14 +00:00
case fv := <-t.chanFullVolumes:
t.SetVolumeCapacityFull(fv)
case cv := <-t.chanCrowdedVolumes:
t.SetVolumeCrowded(cv)
2012-09-19 23:48:04 +00:00
}
}
}()
}
func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
2021-02-16 10:47:02 +00:00
diskType := types.ToDiskType(volumeInfo.DiskType)
2020-12-13 19:59:32 +00:00
vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl, diskType)
if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
return false
}
2018-10-19 03:34:43 +00:00
vl.accessLock.RLock()
defer vl.accessLock.RUnlock()
vidLocations, found := vl.vid2location[volumeInfo.Id]
if !found {
return false
}
for _, dn := range vidLocations.list {
if !volumeInfo.ReadOnly {
2021-02-16 10:47:02 +00:00
disk := dn.getOrCreateDisk(volumeInfo.DiskType)
deltaDiskUsages := newDiskUsages()
2021-02-16 11:03:00 +00:00
deltaDiskUsage := deltaDiskUsages.getOrCreateDisk(types.ToDiskType(volumeInfo.DiskType))
2021-02-16 10:47:02 +00:00
deltaDiskUsage.activeVolumeCount = -1
disk.UpAdjustDiskUsageDelta(deltaDiskUsages)
}
}
return true
2012-09-19 23:48:04 +00:00
}
2021-05-06 10:46:14 +00:00
func (t *Topology) SetVolumeCrowded(volumeInfo storage.VolumeInfo) {
2021-05-06 10:46:14 +00:00
diskType := types.ToDiskType(volumeInfo.DiskType)
vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl, diskType)
vl.SetVolumeCrowded(volumeInfo.Id)
}
2012-09-19 23:48:04 +00:00
func (t *Topology) UnRegisterDataNode(dn *DataNode) {
2016-05-20 06:32:56 +00:00
for _, v := range dn.GetVolumes() {
glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn.Id())
2021-02-16 10:47:02 +00:00
diskType := types.ToDiskType(v.DiskType)
2020-12-13 19:59:32 +00:00
vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, diskType)
2012-09-19 23:48:04 +00:00
vl.SetVolumeUnavailable(dn, v.Id)
}
2021-02-16 10:47:02 +00:00
negativeUsages := dn.GetDiskUsages().negative()
dn.UpAdjustDiskUsageDelta(negativeUsages)
2022-04-07 07:18:28 +00:00
dn.DeltaUpdateVolumes([]storage.VolumeInfo{}, dn.GetVolumes())
dn.DeltaUpdateEcShards([]*erasure_coding.EcVolumeInfo{}, dn.GetEcShards())
if dn.Parent() != nil {
dn.Parent().UnlinkChildNode(dn.Id())
}
2012-09-19 23:48:04 +00:00
}