diff options
| author | yourchanges <yourchanges@gmail.com> | 2015-01-10 02:51:26 +0800 |
|---|---|---|
| committer | yourchanges <yourchanges@gmail.com> | 2015-01-10 02:51:26 +0800 |
| commit | 9601880e323bbdf9540f2c79fb21d66374245b50 (patch) | |
| tree | 14fd3b36a89955ec6e0be6d51186031e978b519d /go/topology/collection.go | |
| parent | f7bcd8e958ef185baeca0c455a397d49fcb62256 (diff) | |
| parent | 2c1a846279c172bcae457e70efa142c29a18892e (diff) | |
| download | seaweedfs-9601880e323bbdf9540f2c79fb21d66374245b50.tar.xz seaweedfs-9601880e323bbdf9540f2c79fb21d66374245b50.zip | |
Merge pull request #2 from chrislusf/master
merge
Diffstat (limited to 'go/topology/collection.go')
| -rw-r--r-- | go/topology/collection.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/go/topology/collection.go b/go/topology/collection.go index 506f43fbf..5437ffd79 100644 --- a/go/topology/collection.go +++ b/go/topology/collection.go @@ -1,36 +1,43 @@ package topology import ( + "fmt" + "github.com/chrislusf/weed-fs/go/storage" + "github.com/chrislusf/weed-fs/go/util" ) type Collection struct { Name string volumeSizeLimit uint64 - storageType2VolumeLayout map[string]*VolumeLayout + storageType2VolumeLayout *util.ConcurrentReadMap } func NewCollection(name string, volumeSizeLimit uint64) *Collection { c := &Collection{Name: name, volumeSizeLimit: volumeSizeLimit} - c.storageType2VolumeLayout = make(map[string]*VolumeLayout) + c.storageType2VolumeLayout = util.NewConcurrentReadMap() return c } +func (c *Collection) String() string { + return fmt.Sprintf("Name:%s, volumeSizeLimit:%d, storageType2VolumeLayout:%v", c.Name, c.volumeSizeLimit, c.storageType2VolumeLayout) +} + func (c *Collection) GetOrCreateVolumeLayout(rp *storage.ReplicaPlacement, ttl *storage.TTL) *VolumeLayout { keyString := rp.String() if ttl != nil { keyString += ttl.String() } - if c.storageType2VolumeLayout[keyString] == nil { - c.storageType2VolumeLayout[keyString] = NewVolumeLayout(rp, ttl, c.volumeSizeLimit) - } - return c.storageType2VolumeLayout[keyString] + vl := c.storageType2VolumeLayout.Get(keyString, func() interface{} { + return NewVolumeLayout(rp, ttl, c.volumeSizeLimit) + }) + return vl.(*VolumeLayout) } func (c *Collection) Lookup(vid storage.VolumeId) []*DataNode { - for _, vl := range c.storageType2VolumeLayout { + for _, vl := range c.storageType2VolumeLayout.Items { if vl != nil { - if list := vl.Lookup(vid); list != nil { + if list := vl.(*VolumeLayout).Lookup(vid); list != nil { return list } } @@ -39,9 +46,9 @@ func (c *Collection) Lookup(vid storage.VolumeId) []*DataNode { } func (c *Collection) ListVolumeServers() (nodes []*DataNode) { - for _, vl := range c.storageType2VolumeLayout { + for _, vl := range c.storageType2VolumeLayout.Items { if vl != nil { - if list := vl.ListVolumeServers(); list != nil { + if list := vl.(*VolumeLayout).ListVolumeServers(); list != nil { nodes = append(nodes, list...) } } |
