aboutsummaryrefslogtreecommitdiff
path: root/go/topology/collection.go
blob: 72ac86522d41dfaa8da2a227e0b3b090e2e6c5e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package topology

import (
	"github.com/aszxqw/weed-fs/go/storage"
)

type Collection struct {
	Name                     string
	volumeSizeLimit          uint64
	storageType2VolumeLayout map[string]*VolumeLayout
}

func NewCollection(name string, volumeSizeLimit uint64) *Collection {
	c := &Collection{Name: name, volumeSizeLimit: volumeSizeLimit}
	c.storageType2VolumeLayout = make(map[string]*VolumeLayout)
	return c
}

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]
}

func (c *Collection) Lookup(vid storage.VolumeId) []*DataNode {
	for _, vl := range c.storageType2VolumeLayout {
		if vl != nil {
			if list := vl.Lookup(vid); list != nil {
				return list
			}
		}
	}
	return nil
}

func (c *Collection) ListVolumeServers() (nodes []*DataNode) {
	for _, vl := range c.storageType2VolumeLayout {
		if vl != nil {
			if list := vl.ListVolumeServers(); list != nil {
				nodes = append(nodes, list...)
			}
		}
	}
	return
}