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.

50 lines
1.2 KiB

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