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.

93 lines
2.8 KiB

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