You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB

  1. package topology
  2. import (
  3. "code.google.com/p/weed-fs/go/glog"
  4. "code.google.com/p/weed-fs/go/storage"
  5. "math/rand"
  6. "time"
  7. )
  8. func (t *Topology) StartRefreshWritableVolumes(garbageThreshold string) {
  9. go func() {
  10. for {
  11. freshThreshHold := time.Now().Unix() - 3*t.pulse //3 times of sleep interval
  12. t.CollectDeadNodeAndFullVolumes(freshThreshHold, t.volumeSizeLimit)
  13. time.Sleep(time.Duration(float32(t.pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
  14. }
  15. }()
  16. go func(garbageThreshold string) {
  17. c := time.Tick(15 * time.Minute)
  18. for _ = range c {
  19. t.Vacuum(garbageThreshold)
  20. }
  21. }(garbageThreshold)
  22. go func() {
  23. for {
  24. select {
  25. case v := <-t.chanFullVolumes:
  26. t.SetVolumeCapacityFull(v)
  27. case dn := <-t.chanRecoveredDataNodes:
  28. t.RegisterRecoveredDataNode(dn)
  29. glog.V(0).Infoln("DataNode", dn, "is back alive!")
  30. case dn := <-t.chanDeadDataNodes:
  31. t.UnRegisterDataNode(dn)
  32. glog.V(0).Infoln("DataNode", dn, "is dead!")
  33. }
  34. }
  35. }()
  36. }
  37. func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
  38. vl := t.GetVolumeLayout(volumeInfo.RepType)
  39. if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
  40. return false
  41. }
  42. for _, dn := range vl.vid2location[volumeInfo.Id].list {
  43. dn.UpAdjustActiveVolumeCountDelta(-1)
  44. }
  45. return true
  46. }
  47. func (t *Topology) UnRegisterDataNode(dn *DataNode) {
  48. for _, v := range dn.volumes {
  49. glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn)
  50. vl := t.GetVolumeLayout(v.RepType)
  51. vl.SetVolumeUnavailable(dn, v.Id)
  52. }
  53. dn.UpAdjustVolumeCountDelta(-dn.GetVolumeCount())
  54. dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
  55. dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
  56. dn.Parent().UnlinkChildNode(dn.Id())
  57. }
  58. func (t *Topology) RegisterRecoveredDataNode(dn *DataNode) {
  59. for _, v := range dn.volumes {
  60. vl := t.GetVolumeLayout(v.RepType)
  61. if vl.isWritable(&v) {
  62. vl.SetVolumeAvailable(dn, v.Id)
  63. }
  64. }
  65. }