2012-09-20 07:48:04 +08:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
2019-02-19 04:11:52 +08:00
|
|
|
"google.golang.org/grpc"
|
2012-09-20 07:48:04 +08:00
|
|
|
"math/rand"
|
|
|
|
"time"
|
2014-10-27 02:34:55 +08:00
|
|
|
|
2016-06-03 09:09:14 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage"
|
2012-09-20 07:48:04 +08:00
|
|
|
)
|
|
|
|
|
2019-02-19 04:11:52 +08:00
|
|
|
func (t *Topology) StartRefreshWritableVolumes(grpcDialOption grpc.DialOption, garbageThreshold 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
|
|
|
|
t.CollectDeadNodeAndFullVolumes(freshThreshHold, t.volumeSizeLimit)
|
|
|
|
}
|
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) {
|
2012-11-24 09:03:27 +08:00
|
|
|
c := time.Tick(15 * time.Minute)
|
2016-05-10 00:58:06 +08:00
|
|
|
for _ = range c {
|
|
|
|
if t.IsLeader() {
|
2019-02-19 04:11:52 +08:00
|
|
|
t.Vacuum(grpcDialOption, garbageThreshold, preallocate)
|
2014-02-10 15:37:29 +08:00
|
|
|
}
|
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 {
|
|
|
|
case v := <-t.chanFullVolumes:
|
|
|
|
t.SetVolumeCapacityFull(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2012-12-04 12:28:12 +08:00
|
|
|
func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
|
2014-09-21 03:38:59 +08:00
|
|
|
vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl)
|
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()
|
|
|
|
|
2012-09-20 17:11:08 +08:00
|
|
|
for _, dn := range vl.vid2location[volumeInfo.Id].list {
|
2014-03-11 02:43:54 +08:00
|
|
|
if !volumeInfo.ReadOnly {
|
|
|
|
dn.UpAdjustActiveVolumeCountDelta(-1)
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
func (t *Topology) UnRegisterDataNode(dn *DataNode) {
|
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())
|
2014-09-21 03:38:59 +08:00
|
|
|
vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
|
2012-09-20 07:48:04 +08:00
|
|
|
vl.SetVolumeUnavailable(dn, v.Id)
|
|
|
|
}
|
2013-01-17 16:56:56 +08:00
|
|
|
dn.UpAdjustVolumeCountDelta(-dn.GetVolumeCount())
|
2019-12-04 13:36:42 +08:00
|
|
|
dn.UpAdjustRemoteVolumeCountDelta(-dn.GetRemoteVolumeCount())
|
2012-09-20 17:11:08 +08:00
|
|
|
dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
|
|
|
|
dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
|
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
|
|
|
}
|