2012-09-19 23:48:04 +00:00
|
|
|
package topology
|
|
|
|
|
|
|
|
import (
|
2013-08-09 06:57:22 +00:00
|
|
|
"code.google.com/p/weed-fs/go/glog"
|
2013-09-02 06:58:21 +00:00
|
|
|
"code.google.com/p/weed-fs/go/storage"
|
2012-09-19 23:48:04 +00:00
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
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 {
|
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)
|
|
|
|
}
|
|
|
|
}()
|
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)
|
|
|
|
for _ = range c {
|
2012-11-24 01:31:54 +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)
|
|
|
|
case dn := <-t.chanRecoveredDataNodes:
|
|
|
|
t.RegisterRecoveredDataNode(dn)
|
2013-08-09 06:57:22 +00:00
|
|
|
glog.V(0).Infoln("DataNode", dn, "is back alive!")
|
2012-09-19 23:48:04 +00:00
|
|
|
case dn := <-t.chanDeadDataNodes:
|
|
|
|
t.UnRegisterDataNode(dn)
|
2013-08-09 06:57:22 +00:00
|
|
|
glog.V(0).Infoln("DataNode", dn, "is dead!")
|
2012-09-19 23:48:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2012-12-04 04:28:12 +00:00
|
|
|
func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
|
2013-11-12 10:21:22 +00:00
|
|
|
vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.RepType)
|
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 {
|
|
|
|
dn.UpAdjustActiveVolumeCountDelta(-1)
|
|
|
|
}
|
2012-12-04 04:28:12 +00:00
|
|
|
return true
|
2012-09-19 23:48:04 +00:00
|
|
|
}
|
|
|
|
func (t *Topology) UnRegisterDataNode(dn *DataNode) {
|
|
|
|
for _, v := range dn.volumes {
|
2013-08-09 06:57:22 +00:00
|
|
|
glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn)
|
2013-11-12 10:21:22 +00:00
|
|
|
vl := t.GetVolumeLayout(v.Collection, v.RepType)
|
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
|
|
|
}
|
|
|
|
func (t *Topology) RegisterRecoveredDataNode(dn *DataNode) {
|
|
|
|
for _, v := range dn.volumes {
|
2013-11-12 10:21:22 +00:00
|
|
|
vl := t.GetVolumeLayout(v.Collection, v.RepType)
|
2012-12-18 00:48:54 +00:00
|
|
|
if vl.isWritable(&v) {
|
2012-09-19 23:48:04 +00:00
|
|
|
vl.SetVolumeAvailable(dn, v.Id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|