seaweedfs/weed-fs/src/pkg/topology/topology_event_handling.go

68 lines
1.8 KiB
Go
Raw Normal View History

2012-09-19 23:48:04 +00:00
package topology
import (
"fmt"
"math/rand"
"pkg/storage"
"time"
)
func (t *Topology) StartRefreshWritableVolumes(garbageThreshold string) {
2012-09-19 23:48:04 +00:00
go func() {
for {
2012-11-12 06:37:12 +00:00
freshThreshHold := time.Now().Unix() - 3*t.pulse //3 times of sleep interval
2012-09-19 23:48:04 +00:00
t.CollectDeadNodeAndFullVolumes(freshThreshHold, t.volumeSizeLimit)
time.Sleep(time.Duration(float32(t.pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
}
}()
go func(garbageThreshold string) {
2012-11-24 01:03:27 +00:00
c := time.Tick(15 * time.Minute)
for _ = range c {
t.Vacuum(garbageThreshold)
2012-11-24 01:03:27 +00:00
}
}(garbageThreshold)
2012-09-19 23:48:04 +00:00
go func() {
for {
select {
case v := <-t.chanFullVolumes:
t.SetVolumeCapacityFull(v)
case dn := <-t.chanRecoveredDataNodes:
t.RegisterRecoveredDataNode(dn)
fmt.Println("DataNode", dn, "is back alive!")
case dn := <-t.chanDeadDataNodes:
t.UnRegisterDataNode(dn)
fmt.Println("DataNode", dn, "is dead!")
}
}
}()
}
func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
2012-09-19 23:48:04 +00:00
vl := t.GetVolumeLayout(volumeInfo.RepType)
if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
return false
}
for _, dn := range vl.vid2location[volumeInfo.Id].list {
dn.UpAdjustActiveVolumeCountDelta(-1)
}
return true
2012-09-19 23:48:04 +00:00
}
func (t *Topology) UnRegisterDataNode(dn *DataNode) {
for _, v := range dn.volumes {
fmt.Println("Removing Volume", v.Id, "from the dead volume server", dn)
vl := t.GetVolumeLayout(v.RepType)
vl.SetVolumeUnavailable(dn, v.Id)
}
dn.UpAdjustVolumeCountDelta(-dn.GetVolumeCount())
dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
dn.Parent().UnlinkChildNode(dn.Id())
2012-09-19 23:48:04 +00:00
}
func (t *Topology) RegisterRecoveredDataNode(dn *DataNode) {
for _, v := range dn.volumes {
vl := t.GetVolumeLayout(v.RepType)
if vl.isWritable(&v) {
2012-09-19 23:48:04 +00:00
vl.SetVolumeAvailable(dn, v.Id)
}
}
}