adjusting maxVolumeCount if volume server changes it

This commit is contained in:
Chris Lu 2012-09-16 19:18:37 -07:00
parent 9b99240584
commit 15ced2398e
3 changed files with 50 additions and 42 deletions

View file

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

View file

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

View file

@ -42,14 +42,17 @@ func (t *Topology) RandomlyReserveOneVolume() (bool, *DataNode, *storage.VolumeI
return ret, node, &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() freeSpace := t.FreeSpace()
for _, node := range except { for _, node := range except {
freeSpace -= node.FreeSpace() freeSpace -= node.FreeSpace()
} }
if freeSpace <= 0 {
return false, nil, nil
}
vid := t.NextVolumeId() vid := t.NextVolumeId()
ret, node := t.ReserveOneVolume(rand.Intn(freeSpace), vid) ret, node := t.ReserveOneVolume(rand.Intn(freeSpace), vid)
return ret, node, vid return ret, node, &vid
} }
func (t *Topology) NextVolumeId() storage.VolumeId { func (t *Topology) NextVolumeId() storage.VolumeId {