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.

57 lines
1.5 KiB

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