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.

51 lines
1.3 KiB

  1. package topology
  2. import (
  3. "github.com/chrislusf/weed-fs/go/storage"
  4. "github.com/chrislusf/weed-fs/go/util"
  5. )
  6. type Collection struct {
  7. Name string
  8. volumeSizeLimit uint64
  9. storageType2VolumeLayout *util.ConcurrentReadMap
  10. }
  11. func NewCollection(name string, volumeSizeLimit uint64) *Collection {
  12. c := &Collection{Name: name, volumeSizeLimit: volumeSizeLimit}
  13. c.storageType2VolumeLayout = util.NewConcurrentReadMap()
  14. return c
  15. }
  16. func (c *Collection) GetOrCreateVolumeLayout(rp *storage.ReplicaPlacement, ttl *storage.TTL) *VolumeLayout {
  17. keyString := rp.String()
  18. if ttl != nil {
  19. keyString += ttl.String()
  20. }
  21. vl := c.storageType2VolumeLayout.Get(keyString, func() interface{} {
  22. return NewVolumeLayout(rp, ttl, c.volumeSizeLimit)
  23. })
  24. return vl.(*VolumeLayout)
  25. }
  26. func (c *Collection) Lookup(vid storage.VolumeId) []*DataNode {
  27. for _, vl := range c.storageType2VolumeLayout.Items {
  28. if vl != nil {
  29. if list := vl.(*VolumeLayout).Lookup(vid); list != nil {
  30. return list
  31. }
  32. }
  33. }
  34. return nil
  35. }
  36. func (c *Collection) ListVolumeServers() (nodes []*DataNode) {
  37. for _, vl := range c.storageType2VolumeLayout.Items {
  38. if vl != nil {
  39. if list := vl.(*VolumeLayout).ListVolumeServers(); list != nil {
  40. nodes = append(nodes, list...)
  41. }
  42. }
  43. }
  44. return
  45. }