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.

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