2012-09-19 23:48:04 +00:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2016-06-03 01:09:14 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage"
|
2012-09-19 23:48:04 +00:00
|
|
|
)
|
|
|
|
|
2012-11-24 01:31:54 +00:00
|
|
|
func (t *Topology) StartRefreshWritableVolumes(garbageThreshold string) {
|
2012-09-19 23:48:04 +00:00
|
|
|
go func() {
|
|
|
|
for {
|
2014-03-16 06:03:49 +00:00
|
|
|
if t.IsLeader() {
|
2014-02-10 07:37:29 +00:00
|
|
|
freshThreshHold := time.Now().Unix() - 3*t.pulse //3 times of sleep interval
|
|
|
|
t.CollectDeadNodeAndFullVolumes(freshThreshHold, t.volumeSizeLimit)
|
|
|
|
}
|
2012-09-19 23:48:04 +00:00
|
|
|
time.Sleep(time.Duration(float32(t.pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
|
|
|
|
}
|
|
|
|
}()
|
2012-11-24 01:31:54 +00:00
|
|
|
go func(garbageThreshold string) {
|
2012-11-24 01:03:27 +00:00
|
|
|
c := time.Tick(15 * time.Minute)
|
2016-05-09 16:58:06 +00:00
|
|
|
for _ = range c {
|
|
|
|
if t.IsLeader() {
|
2014-02-10 07:37:29 +00:00
|
|
|
t.Vacuum(garbageThreshold)
|
|
|
|
}
|
2012-11-24 01:03:27 +00:00
|
|
|
}
|
2012-11-24 01:31:54 +00:00
|
|
|
}(garbageThreshold)
|
2012-09-19 23:48:04 +00:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case v := <-t.chanFullVolumes:
|
|
|
|
t.SetVolumeCapacityFull(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2012-12-04 04:28:12 +00:00
|
|
|
func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
|
2014-09-20 19:38:59 +00:00
|
|
|
vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl)
|
2012-12-04 04:28:12 +00:00
|
|
|
if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
|
|
|
|
return false
|
|
|
|
}
|
2012-09-20 09:11:08 +00:00
|
|
|
for _, dn := range vl.vid2location[volumeInfo.Id].list {
|
2014-03-10 18:43:54 +00:00
|
|
|
if !volumeInfo.ReadOnly {
|
|
|
|
dn.UpAdjustActiveVolumeCountDelta(-1)
|
|
|
|
}
|
2012-09-20 09:11:08 +00:00
|
|
|
}
|
2012-12-04 04:28:12 +00:00
|
|
|
return true
|
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() {
|
2017-01-10 09:30:00 +00:00
|
|
|
glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn.Id())
|
2014-09-20 19:38:59 +00:00
|
|
|
vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
|
2012-09-19 23:48:04 +00:00
|
|
|
vl.SetVolumeUnavailable(dn, v.Id)
|
|
|
|
}
|
2013-01-17 08:56:56 +00:00
|
|
|
dn.UpAdjustVolumeCountDelta(-dn.GetVolumeCount())
|
2012-09-20 09:11:08 +00:00
|
|
|
dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
|
|
|
|
dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
|
|
|
|
dn.Parent().UnlinkChildNode(dn.Id())
|
2012-09-19 23:48:04 +00:00
|
|
|
}
|