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.

66 lines
1.8 KiB

9 years ago
  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 float64, 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 float64) {
  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. vl.accessLock.RLock()
  41. defer vl.accessLock.RUnlock()
  42. for _, dn := range vl.vid2location[volumeInfo.Id].list {
  43. if !volumeInfo.ReadOnly {
  44. dn.UpAdjustActiveVolumeCountDelta(-1)
  45. }
  46. }
  47. return true
  48. }
  49. func (t *Topology) UnRegisterDataNode(dn *DataNode) {
  50. for _, v := range dn.GetVolumes() {
  51. glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn.Id())
  52. vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
  53. vl.SetVolumeUnavailable(dn, v.Id)
  54. }
  55. dn.UpAdjustVolumeCountDelta(-dn.GetVolumeCount())
  56. dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
  57. dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
  58. if dn.Parent() != nil {
  59. dn.Parent().UnlinkChildNode(dn.Id())
  60. }
  61. }