topology_event_handling.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package topology
  2. import (
  3. "math/rand"
  4. "time"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/storage"
  7. )
  8. func (t *Topology) StartRefreshWritableVolumes(garbageThreshold string, preallocate int64) {
  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. for _ = range c {
  21. if t.IsLeader() {
  22. t.Vacuum(garbageThreshold, preallocate)
  23. }
  24. }
  25. }(garbageThreshold)
  26. go func() {
  27. for {
  28. select {
  29. case v := <-t.chanFullVolumes:
  30. t.SetVolumeCapacityFull(v)
  31. }
  32. }
  33. }()
  34. }
  35. func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
  36. vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl)
  37. if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
  38. return false
  39. }
  40. for _, dn := range vl.vid2location[volumeInfo.Id].list {
  41. if !volumeInfo.ReadOnly {
  42. dn.UpAdjustActiveVolumeCountDelta(-1)
  43. }
  44. }
  45. return true
  46. }
  47. func (t *Topology) UnRegisterDataNode(dn *DataNode) {
  48. for _, v := range dn.GetVolumes() {
  49. glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn.Id())
  50. vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
  51. vl.SetVolumeUnavailable(dn, v.Id)
  52. }
  53. dn.UpAdjustVolumeCountDelta(-dn.GetVolumeCount())
  54. dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
  55. dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
  56. if dn.Parent() != nil {
  57. dn.Parent().UnlinkChildNode(dn.Id())
  58. }
  59. }