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.

63 lines
1.7 KiB

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