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.

77 lines
2.1 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, 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)
  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 v := <-t.chanFullVolumes:
  32. t.SetVolumeCapacityFull(v)
  33. }
  34. }
  35. }()
  36. }
  37. func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
  38. diskType := types.ToDiskType(volumeInfo.DiskType)
  39. vl := t.GetVolumeLayout(volumeInfo.Collection, volumeInfo.ReplicaPlacement, volumeInfo.Ttl, diskType)
  40. if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
  41. return false
  42. }
  43. vl.accessLock.RLock()
  44. defer vl.accessLock.RUnlock()
  45. for _, dn := range vl.vid2location[volumeInfo.Id].list {
  46. if !volumeInfo.ReadOnly {
  47. disk := dn.getOrCreateDisk(volumeInfo.DiskType)
  48. deltaDiskUsages := newDiskUsages()
  49. deltaDiskUsage := deltaDiskUsages.getOrCreateDisk(types.ToDiskType(volumeInfo.DiskType))
  50. deltaDiskUsage.activeVolumeCount = -1
  51. disk.UpAdjustDiskUsageDelta(deltaDiskUsages)
  52. }
  53. }
  54. return true
  55. }
  56. func (t *Topology) UnRegisterDataNode(dn *DataNode) {
  57. for _, v := range dn.GetVolumes() {
  58. glog.V(0).Infoln("Removing Volume", v.Id, "from the dead volume server", dn.Id())
  59. diskType := types.ToDiskType(v.DiskType)
  60. vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, diskType)
  61. vl.SetVolumeUnavailable(dn, v.Id)
  62. }
  63. negativeUsages := dn.GetDiskUsages().negative()
  64. dn.UpAdjustDiskUsageDelta(negativeUsages)
  65. if dn.Parent() != nil {
  66. dn.Parent().UnlinkChildNode(dn.Id())
  67. }
  68. }