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.

73 lines
2.1 KiB

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