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.

49 lines
1.3 KiB

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