Browse Source

adjusting maxVolumeCount if volume server changes it

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

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

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

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

@ -17,21 +17,22 @@ func NewRack(id string) *Rack {
return r
}
func (r *Rack) MatchLocationRange(ip string) bool{
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{
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) {
if dn.MatchLocation(ip, port) {
dn.NodeImpl.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount)
return dn
}
}
dn := NewDataNode("DataNode"+ip+":"+strconv.Itoa(port))
dn := NewDataNode("DataNode" + ip + ":" + strconv.Itoa(port))
dn.Ip = ip
dn.Port = port
dn.PublicUrl = publicUrl
@ -40,7 +41,7 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVol
return dn
}
func (rack *Rack) ToMap() interface{}{
func (rack *Rack) ToMap() interface{} {
m := make(map[string]interface{})
m["Free"] = rack.FreeSpace()
var dns []interface{}

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

@ -34,7 +34,7 @@ func NewTopology(id string, dirname string, filename string, volumeSizeLimit uin
}
func (t *Topology) RandomlyReserveOneVolume() (bool, *DataNode, *storage.VolumeId) {
if t.FreeSpace()<=0 {
if t.FreeSpace() <= 0 {
return false, nil, nil
}
vid := t.NextVolumeId()
@ -42,14 +42,17 @@ func (t *Topology) RandomlyReserveOneVolume() (bool, *DataNode, *storage.VolumeI
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