2012-08-24 03:56:09 +00:00
|
|
|
package topology
|
|
|
|
|
2012-08-28 08:04:39 +00:00
|
|
|
import (
|
|
|
|
"pkg/storage"
|
|
|
|
)
|
2012-08-24 03:56:09 +00:00
|
|
|
|
2012-08-24 05:33:37 +00:00
|
|
|
type RackId uint32
|
2012-08-24 03:56:09 +00:00
|
|
|
type Rack struct {
|
2012-08-24 05:33:37 +00:00
|
|
|
Id RackId
|
|
|
|
nodes map[NodeId]*Node
|
|
|
|
ipRange IpRange
|
2012-08-28 08:04:39 +00:00
|
|
|
|
|
|
|
//transient
|
|
|
|
allocation StorageCapacity
|
|
|
|
dataCenter *DataCenter
|
|
|
|
}
|
|
|
|
func (rack *Rack) CreateOneVolume(r int, vid storage.VolumeId) storage.VolumeId {
|
|
|
|
for _, node := range rack.nodes {
|
|
|
|
freeSpace := node.maxVolumeCount - len(node.volumes)
|
|
|
|
if r > freeSpace {
|
|
|
|
r -= freeSpace
|
|
|
|
} else {
|
|
|
|
node.CreateOneVolume(r, vid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vid
|
|
|
|
}
|
|
|
|
func (r *Rack) AddVolume(n *Node, v *storage.VolumeInfo){
|
|
|
|
r.allocation.countVolumeCount += 1
|
|
|
|
r.dataCenter.AddVolume(r,v)
|
|
|
|
}
|
|
|
|
func (r *Rack) AddNode(n *Node){
|
|
|
|
r.nodes[n.Ip] = n
|
|
|
|
r.allocation.countVolumeCount += len(n.volumes)
|
|
|
|
r.allocation.maxVolumeCount += n.maxVolumeCount
|
|
|
|
r.dataCenter.AddNode(r,n)
|
|
|
|
}
|
|
|
|
func (r *Rack) RemoveNode(n *Node){
|
|
|
|
delete(r.nodes,n.Ip)
|
|
|
|
r.allocation.countVolumeCount -= len(n.volumes)
|
|
|
|
r.allocation.maxVolumeCount -= n.maxVolumeCount
|
|
|
|
r.dataCenter.RemoveNode(r,n)
|
2012-08-24 03:56:09 +00:00
|
|
|
}
|