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.

86 lines
2.5 KiB

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