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.

72 lines
2.1 KiB

9 years ago
  1. package topology
  2. import (
  3. "google.golang.org/grpc"
  4. "math/rand"
  5. "time"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/storage"
  8. )
  9. func (t *Topology) StartRefreshWritableVolumes(grpcDialOption grpc.DialOption, garbageThreshold float64, preallocate int64) {
  10. go func() {
  11. for {
  12. if t.IsLeader() {
  13. freshThreshHold := time.Now().Unix() - 3*t.pulse //3 times of sleep interval
  14. t.CollectDeadNodeAndFullVolumes(freshThreshHold, t.volumeSizeLimit)
  15. }
  16. time.Sleep(time.Duration(float32(t.pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
  17. }
  18. }()
  19. go func(garbageThreshold float64) {
  20. c := time.Tick(15 * time.Minute)
  21. for _ = range c {
  22. if t.IsLeader() {
  23. t.Vacuum(grpcDialOption, garbageThreshold, preallocate)
  24. }
  25. }
  26. }(garbageThreshold)
  27. go func() {
  28. for {
  29. select {
  30. case v := <-t.chanFullVolumes:
  31. t.SetVolumeCapacityFull(v)
  32. }
  33. }
  34. }()
  35. }
  36. func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
  37. diskType, _ := storage.ToDiskType(volumeInfo.DiskType)
  38. vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl, diskType)
  39. if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
  40. return false
  41. }
  42. vl.accessLock.RLock()
  43. defer vl.accessLock.RUnlock()
  44. for _, dn := range vl.vid2location[volumeInfo.Id].list {
  45. if !volumeInfo.ReadOnly {
  46. dn.UpAdjustActiveVolumeCountDelta(-1)
  47. }
  48. }
  49. return true
  50. }
  51. func (t *Topology) UnRegisterDataNode(dn *DataNode) {
  52. for _, v := range dn.GetVolumes() {
  53. glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn.Id())
  54. diskType, _ := storage.ToDiskType(v.DiskType)
  55. vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, diskType)
  56. vl.SetVolumeUnavailable(dn, v.Id)
  57. }
  58. dn.UpAdjustVolumeCountDelta(-dn.GetVolumeCount())
  59. dn.UpAdjustSsdVolumeCountDelta(-dn.GetSsdVolumeCount())
  60. dn.UpAdjustRemoteVolumeCountDelta(-dn.GetRemoteVolumeCount())
  61. dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
  62. dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
  63. dn.UpAdjustMaxSsdVolumeCountDelta(-dn.GetMaxSsdVolumeCount())
  64. if dn.Parent() != nil {
  65. dn.Parent().UnlinkChildNode(dn.Id())
  66. }
  67. }