Chris Lu
13 years ago
6 changed files with 80 additions and 151 deletions
-
8weed-fs/src/pkg/topology/capacity.go
-
47weed-fs/src/pkg/topology/data_center.go
-
58weed-fs/src/pkg/topology/node.go
-
36weed-fs/src/pkg/topology/rack.go
-
21weed-fs/src/pkg/topology/server.go
-
51weed-fs/src/pkg/topology/topology.go
@ -1,8 +0,0 @@ |
|||
package topology |
|||
|
|||
import () |
|||
|
|||
type StorageCapacity struct { |
|||
countVolumeCount int |
|||
maxVolumeCount int |
|||
} |
@ -1,54 +1,9 @@ |
|||
package topology |
|||
|
|||
import ( |
|||
"pkg/storage" |
|||
) |
|||
|
|||
type DataCenterId string |
|||
type DataCenter struct { |
|||
Id DataCenterId |
|||
racks map[RackId]*Rack |
|||
Node |
|||
ipRange IpRange |
|||
|
|||
//transient
|
|||
allocation StorageCapacity |
|||
topology *Topology |
|||
} |
|||
|
|||
func (d *DataCenter) CreateOneVolume(r int, vid storage.VolumeId) storage.VolumeId { |
|||
for _, rack := range d.racks { |
|||
freeSpace := rack.allocation.maxVolumeCount - rack.allocation.countVolumeCount |
|||
if r > freeSpace { |
|||
r -= freeSpace |
|||
} else { |
|||
rack.CreateOneVolume(r, vid) |
|||
} |
|||
} |
|||
return vid |
|||
} |
|||
func (d *DataCenter) AddVolume(rack *Rack, v *storage.VolumeInfo) { |
|||
d.allocation.countVolumeCount += 1 |
|||
d.topology.AddVolume(d, v) |
|||
} |
|||
func (d *DataCenter) AddNode(rack *Rack, n *Node) { |
|||
d.allocation.countVolumeCount += len(n.volumes) |
|||
d.allocation.maxVolumeCount += n.maxVolumeCount |
|||
d.topology.AddNode(d, n) |
|||
} |
|||
func (d *DataCenter) RemoveNode(rack *Rack, n *Node) { |
|||
d.allocation.countVolumeCount -= len(n.volumes) |
|||
d.allocation.maxVolumeCount -= n.maxVolumeCount |
|||
d.topology.RemoveNode(d, n) |
|||
} |
|||
func (d *DataCenter) AddRack(rack *Rack) { |
|||
d.racks[rack.Id] = rack |
|||
d.allocation.countVolumeCount += rack.allocation.countVolumeCount |
|||
d.allocation.maxVolumeCount += rack.allocation.maxVolumeCount |
|||
d.topology.AddRack(d, rack) |
|||
} |
|||
func (d *DataCenter) RemoveRack(rack *Rack) { |
|||
delete(d.racks, rack.Id) |
|||
d.allocation.countVolumeCount -= rack.allocation.countVolumeCount |
|||
d.allocation.maxVolumeCount -= rack.allocation.maxVolumeCount |
|||
d.topology.AddRack(d, rack) |
|||
} |
@ -1,43 +1,9 @@ |
|||
package topology |
|||
|
|||
import ( |
|||
"pkg/storage" |
|||
) |
|||
|
|||
type RackId uint32 |
|||
type Rack struct { |
|||
Id RackId |
|||
nodes map[NodeId]*Node |
|||
Node |
|||
ipRange IpRange |
|||
|
|||
//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) |
|||
} |
@ -0,0 +1,21 @@ |
|||
package topology |
|||
|
|||
import ( |
|||
"pkg/storage" |
|||
) |
|||
|
|||
type Server struct { |
|||
Node |
|||
volumes map[storage.VolumeId]*storage.VolumeInfo |
|||
Ip NodeId |
|||
Port int |
|||
PublicUrl string |
|||
} |
|||
func (s *Server) CreateOneVolume(r int, vid storage.VolumeId) storage.VolumeId { |
|||
s.AddVolume(&storage.VolumeInfo{Id:vid, Size: 32*1024*1024*1024}) |
|||
return vid |
|||
} |
|||
func (s *Server) AddVolume(v *storage.VolumeInfo){ |
|||
s.volumes[v.Id] = v |
|||
s.Node.AddVolume(v) |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue