seaweedfs/go/topology/topology_event_handling.go

75 lines
2.1 KiB
Go
Raw Normal View History

2012-09-20 07:48:04 +08:00
package topology
import (
"math/rand"
"time"
"github.com/chrislusf/seaweedfs/go/glog"
"github.com/chrislusf/seaweedfs/go/storage"
2012-09-20 07:48:04 +08:00
)
func (t *Topology) StartRefreshWritableVolumes(garbageThreshold string) {
2012-09-20 07:48:04 +08:00
go func() {
for {
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)
}
}()
go func(garbageThreshold string) {
2012-11-24 09:03:27 +08:00
c := time.Tick(15 * time.Minute)
for _ = range c {
if t.IsLeader() {
2014-02-10 15:37:29 +08:00
t.Vacuum(garbageThreshold)
}
2012-11-24 09:03:27 +08:00
}
}(garbageThreshold)
2012-09-20 07:48:04 +08:00
go func() {
for {
select {
case v := <-t.chanFullVolumes:
t.SetVolumeCapacityFull(v)
case dn := <-t.chanRecoveredDataNodes:
t.RegisterRecoveredDataNode(dn)
glog.V(0).Infoln("DataNode", dn, "is back alive!")
2012-09-20 07:48:04 +08:00
case dn := <-t.chanDeadDataNodes:
t.UnRegisterDataNode(dn)
glog.V(0).Infoln("DataNode", dn, "is dead!")
2012-09-20 07:48:04 +08:00
}
}
}()
}
func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl)
if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
return false
}
for _, dn := range vl.vid2location[volumeInfo.Id].list {
if !volumeInfo.ReadOnly {
dn.UpAdjustActiveVolumeCountDelta(-1)
}
}
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() {
glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn)
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())
dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
dn.Parent().UnlinkChildNode(dn.Id())
2012-09-20 07:48:04 +08:00
}
func (t *Topology) RegisterRecoveredDataNode(dn *DataNode) {
2016-05-20 14:32:56 +08:00
for _, v := range dn.GetVolumes() {
vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
if vl.isWritable(&v) {
2012-09-20 07:48:04 +08:00
vl.SetVolumeAvailable(dn, v.Id)
}
}
}