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.

38 lines
1.1 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.LengthRelicationType)
  14. return c
  15. }
  16. func (c *Collection) GetOrCreateVolumeLayout(repType storage.ReplicationType) *VolumeLayout {
  17. replicationTypeIndex := repType.GetReplicationLevelIndex()
  18. if c.replicaType2VolumeLayout[replicationTypeIndex] == nil {
  19. glog.V(0).Infoln("collection", c.Name, "adding replication type", repType)
  20. c.replicaType2VolumeLayout[replicationTypeIndex] = NewVolumeLayout(repType, c.volumeSizeLimit)
  21. }
  22. return c.replicaType2VolumeLayout[replicationTypeIndex]
  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. }