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