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. 1
      weed-fs/src/pkg/topology/rack.go
  3. 7
      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])
}

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

@ -28,6 +28,7 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVol
for _, c := range r.Children() {
dn := c.(*DataNode)
if dn.MatchLocation(ip, port) {
dn.NodeImpl.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount)
return dn
}
}

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

@ -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