2012-09-20 07:48:04 +08:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
2024-08-30 00:52:21 +08:00
|
|
|
"math/rand/v2"
|
2022-12-28 17:36:44 +08:00
|
|
|
"time"
|
|
|
|
|
2022-08-13 04:11:09 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
2019-02-19 04:11:52 +08:00
|
|
|
"google.golang.org/grpc"
|
2014-10-27 02:34:55 +08:00
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage"
|
2012-09-20 07:48:04 +08:00
|
|
|
)
|
|
|
|
|
2024-08-22 13:53:54 +08:00
|
|
|
func (t *Topology) StartRefreshWritableVolumes(grpcDialOption grpc.DialOption, garbageThreshold float64, concurrentVacuumLimitPerVolumeServer int, growThreshold float64, preallocate int64) {
|
2012-09-20 07:48:04 +08:00
|
|
|
go func() {
|
|
|
|
for {
|
2014-03-16 14:03:49 +08:00
|
|
|
if t.IsLeader() {
|
2014-02-10 15: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-10 15:37:29 +08:00
|
|
|
}
|
2012-09-20 07:48:04 +08:00
|
|
|
time.Sleep(time.Duration(float32(t.pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
|
|
|
|
}
|
|
|
|
}()
|
2018-10-15 14:12:43 +08:00
|
|
|
go func(garbageThreshold float64) {
|
2022-08-13 04:11:09 +08:00
|
|
|
for {
|
2016-05-10 00:58:06 +08:00
|
|
|
if t.IsLeader() {
|
2022-12-28 17:36:44 +08:00
|
|
|
if !t.isDisableVacuum {
|
2024-08-22 13:53:54 +08:00
|
|
|
t.Vacuum(grpcDialOption, garbageThreshold, concurrentVacuumLimitPerVolumeServer, 0, "", preallocate)
|
2022-12-28 17:36:44 +08:00
|
|
|
}
|
2022-08-13 04:11:09 +08:00
|
|
|
} else {
|
|
|
|
stats.MasterReplicaPlacementMismatch.Reset()
|
2014-02-10 15:37:29 +08:00
|
|
|
}
|
2022-08-13 04:11:09 +08:00
|
|
|
time.Sleep(14*time.Minute + time.Duration(120*rand.Float32())*time.Second)
|
2012-11-24 09:03:27 +08:00
|
|
|
}
|
2012-11-24 09:31:54 +08:00
|
|
|
}(garbageThreshold)
|
2012-09-20 07:48:04 +08: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-20 07:48:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2021-05-12 01:05:31 +08:00
|
|
|
func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
|
2021-02-16 18:47:02 +08:00
|
|
|
diskType := types.ToDiskType(volumeInfo.DiskType)
|
2020-12-14 03:59:32 +08:00
|
|
|
vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl, diskType)
|
2012-12-04 12:28:12 +08:00
|
|
|
if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
|
|
|
|
return false
|
|
|
|
}
|
2018-10-19 11:34:43 +08:00
|
|
|
|
|
|
|
vl.accessLock.RLock()
|
|
|
|
defer vl.accessLock.RUnlock()
|
|
|
|
|
2021-05-10 17:39:52 +08:00
|
|
|
vidLocations, found := vl.vid2location[volumeInfo.Id]
|
|
|
|
if !found {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, dn := range vidLocations.list {
|
2014-03-11 02:43:54 +08:00
|
|
|
if !volumeInfo.ReadOnly {
|
2021-02-16 18:47:02 +08:00
|
|
|
|
|
|
|
disk := dn.getOrCreateDisk(volumeInfo.DiskType)
|
|
|
|
deltaDiskUsages := newDiskUsages()
|
2021-02-16 19:03:00 +08:00
|
|
|
deltaDiskUsage := deltaDiskUsages.getOrCreateDisk(types.ToDiskType(volumeInfo.DiskType))
|
2021-02-16 18:47:02 +08:00
|
|
|
deltaDiskUsage.activeVolumeCount = -1
|
|
|
|
disk.UpAdjustDiskUsageDelta(deltaDiskUsages)
|
|
|
|
|
2014-03-11 02:43:54 +08:00
|
|
|
}
|
2012-09-20 17:11:08 +08:00
|
|
|
}
|
2012-12-04 12:28:12 +08:00
|
|
|
return true
|
2012-09-20 07:48:04 +08:00
|
|
|
}
|
2021-05-06 18:46:14 +08:00
|
|
|
|
2021-05-12 01:05:31 +08: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-20 07:48:04 +08:00
|
|
|
func (t *Topology) UnRegisterDataNode(dn *DataNode) {
|
2023-05-30 23:20:00 +08:00
|
|
|
dn.IsTerminating = true
|
2016-05-20 14:32:56 +08:00
|
|
|
for _, v := range dn.GetVolumes() {
|
2017-01-10 17:30:00 +08:00
|
|
|
glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn.Id())
|
2021-02-16 18:47:02 +08:00
|
|
|
diskType := types.ToDiskType(v.DiskType)
|
2020-12-14 03:59:32 +08:00
|
|
|
vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, diskType)
|
2012-09-20 07:48:04 +08:00
|
|
|
vl.SetVolumeUnavailable(dn, v.Id)
|
|
|
|
}
|
2021-02-16 18:47:02 +08:00
|
|
|
|
2024-06-21 06:29:36 +08:00
|
|
|
// unregister ec shards when volume server disconnected
|
|
|
|
for _, s := range dn.GetEcShards() {
|
|
|
|
t.UnRegisterEcShards(s, dn)
|
|
|
|
}
|
|
|
|
|
2021-02-16 18:47:02 +08:00
|
|
|
negativeUsages := dn.GetDiskUsages().negative()
|
|
|
|
dn.UpAdjustDiskUsageDelta(negativeUsages)
|
2022-04-07 15:18:28 +08:00
|
|
|
dn.DeltaUpdateVolumes([]storage.VolumeInfo{}, dn.GetVolumes())
|
|
|
|
dn.DeltaUpdateEcShards([]*erasure_coding.EcVolumeInfo{}, dn.GetEcShards())
|
2017-06-16 23:27:50 +08:00
|
|
|
if dn.Parent() != nil {
|
|
|
|
dn.Parent().UnlinkChildNode(dn.Id())
|
|
|
|
}
|
2012-09-20 07:48:04 +08:00
|
|
|
}
|