Browse Source

adjusting maxVolumeCount if volume server changes it

pull/2/head
Chris Lu 12 years ago
parent
commit
15ced2398e
  1. 12
      weed-fs/src/pkg/replication/volume_growth.go
  2. 67
      weed-fs/src/pkg/topology/rack.go
  3. 13
      weed-fs/src/pkg/topology/topology.go

12
weed-fs/src/pkg/replication/volume_growth.go

@ -63,8 +63,10 @@ func (vg *VolumeGrowth) GrowByCountAndType(count int, repType storage.Replicatio
if ret {
var servers []*topology.DataNode
for _, n := range picked {
if ok, server := n.ReserveOneVolume(rand.Intn(n.FreeSpace()), vid); ok {
servers = append(servers, server)
if n.FreeSpace() > 0 {
if ok, server := n.ReserveOneVolume(rand.Intn(n.FreeSpace()), vid); ok {
servers = append(servers, server)
}
}
}
if len(servers) == 2 {
@ -80,8 +82,10 @@ func (vg *VolumeGrowth) GrowByCountAndType(count int, repType storage.Replicatio
if ret {
var servers []*topology.DataNode
for _, n := range picked {
if ok, server := n.ReserveOneVolume(rand.Intn(n.FreeSpace()), vid); ok {
servers = append(servers, server)
if n.FreeSpace() > 0 {
if ok, server := n.ReserveOneVolume(rand.Intn(n.FreeSpace()), vid); ok {
servers = append(servers, server)
}
}
}
if len(servers) == 3 {

67
weed-fs/src/pkg/topology/rack.go

@ -1,7 +1,7 @@
package topology
import (
"strconv"
"strconv"
)
type Rack struct {
@ -11,43 +11,44 @@ type Rack struct {
func NewRack(id string) *Rack {
r := &Rack{}
r.id = NodeId(id)
r.nodeType = "Rack"
r.children = make(map[NodeId]Node)
r.id = NodeId(id)
r.nodeType = "Rack"
r.children = make(map[NodeId]Node)
return r
}
func (r *Rack) MatchLocationRange(ip string) bool{
if r.ipRange == nil {
return true
}
return r.ipRange.Match(ip)
func (r *Rack) MatchLocationRange(ip string) bool {
if r.ipRange == nil {
return true
}
return r.ipRange.Match(ip)
}
func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVolumeCount int) *DataNode{
for _, c := range r.Children() {
dn := c.(*DataNode)
if dn.MatchLocation(ip,port) {
return dn
}
}
dn := NewDataNode("DataNode"+ip+":"+strconv.Itoa(port))
dn.Ip = ip
dn.Port = port
dn.PublicUrl = publicUrl
dn.maxVolumeCount = maxVolumeCount
r.LinkChildNode(dn)
return dn
func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVolumeCount int) *DataNode {
for _, c := range r.Children() {
dn := c.(*DataNode)
if dn.MatchLocation(ip, port) {
dn.NodeImpl.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount)
return dn
}
}
dn := NewDataNode("DataNode" + ip + ":" + strconv.Itoa(port))
dn.Ip = ip
dn.Port = port
dn.PublicUrl = publicUrl
dn.maxVolumeCount = maxVolumeCount
r.LinkChildNode(dn)
return dn
}
func (rack *Rack) ToMap() interface{}{
m := make(map[string]interface{})
m["Free"] = rack.FreeSpace()
var dns []interface{}
for _, c := range rack.Children() {
dn := c.(*DataNode)
dns = append(dns, dn.ToMap())
}
m["DataNodes"] = dns
return m
func (rack *Rack) ToMap() interface{} {
m := make(map[string]interface{})
m["Free"] = rack.FreeSpace()
var dns []interface{}
for _, c := range rack.Children() {
dn := c.(*DataNode)
dns = append(dns, dn.ToMap())
}
m["DataNodes"] = dns
return m
}

13
weed-fs/src/pkg/topology/topology.go

@ -34,22 +34,25 @@ func NewTopology(id string, dirname string, filename string, volumeSizeLimit uin
}
func (t *Topology) RandomlyReserveOneVolume() (bool, *DataNode, *storage.VolumeId) {
if t.FreeSpace()<=0 {
return false, nil, nil
}
if t.FreeSpace() <= 0 {
return false, nil, nil
}
vid := t.NextVolumeId()
ret, node := t.ReserveOneVolume(rand.Intn(t.FreeSpace()), vid)
return ret, node, &vid
}
func (t *Topology) RandomlyReserveOneVolumeExcept(except []Node) (bool, *DataNode, storage.VolumeId) {
func (t *Topology) RandomlyReserveOneVolumeExcept(except []Node) (bool, *DataNode, *storage.VolumeId) {
freeSpace := t.FreeSpace()
for _, node := range except {
freeSpace -= node.FreeSpace()
}
if freeSpace <= 0 {
return false, nil, nil
}
vid := t.NextVolumeId()
ret, node := t.ReserveOneVolume(rand.Intn(freeSpace), vid)
return ret, node, vid
return ret, node, &vid
}
func (t *Topology) NextVolumeId() storage.VolumeId {

Loading…
Cancel
Save