mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
adjusting maxVolumeCount if volume server changes it
This commit is contained in:
parent
9b99240584
commit
15ced2398e
|
@ -63,8 +63,10 @@ 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 ok, server := n.ReserveOneVolume(rand.Intn(n.FreeSpace()), vid); ok {
|
if n.FreeSpace() > 0 {
|
||||||
servers = append(servers, server)
|
if ok, server := n.ReserveOneVolume(rand.Intn(n.FreeSpace()), vid); ok {
|
||||||
|
servers = append(servers, server)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(servers) == 2 {
|
if len(servers) == 2 {
|
||||||
|
@ -80,8 +82,10 @@ 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 ok, server := n.ReserveOneVolume(rand.Intn(n.FreeSpace()), vid); ok {
|
if n.FreeSpace() > 0 {
|
||||||
servers = append(servers, server)
|
if ok, server := n.ReserveOneVolume(rand.Intn(n.FreeSpace()), vid); ok {
|
||||||
|
servers = append(servers, server)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(servers) == 3 {
|
if len(servers) == 3 {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package topology
|
package topology
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Rack struct {
|
type Rack struct {
|
||||||
|
@ -11,43 +11,44 @@ type Rack struct {
|
||||||
|
|
||||||
func NewRack(id string) *Rack {
|
func NewRack(id string) *Rack {
|
||||||
r := &Rack{}
|
r := &Rack{}
|
||||||
r.id = NodeId(id)
|
r.id = NodeId(id)
|
||||||
r.nodeType = "Rack"
|
r.nodeType = "Rack"
|
||||||
r.children = make(map[NodeId]Node)
|
r.children = make(map[NodeId]Node)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Rack) MatchLocationRange(ip string) bool{
|
func (r *Rack) MatchLocationRange(ip string) bool {
|
||||||
if r.ipRange == nil {
|
if r.ipRange == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return r.ipRange.Match(ip)
|
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() {
|
for _, c := range r.Children() {
|
||||||
dn := c.(*DataNode)
|
dn := c.(*DataNode)
|
||||||
if dn.MatchLocation(ip,port) {
|
if dn.MatchLocation(ip, port) {
|
||||||
return dn
|
dn.NodeImpl.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount)
|
||||||
}
|
return dn
|
||||||
}
|
}
|
||||||
dn := NewDataNode("DataNode"+ip+":"+strconv.Itoa(port))
|
}
|
||||||
dn.Ip = ip
|
dn := NewDataNode("DataNode" + ip + ":" + strconv.Itoa(port))
|
||||||
dn.Port = port
|
dn.Ip = ip
|
||||||
dn.PublicUrl = publicUrl
|
dn.Port = port
|
||||||
dn.maxVolumeCount = maxVolumeCount
|
dn.PublicUrl = publicUrl
|
||||||
r.LinkChildNode(dn)
|
dn.maxVolumeCount = maxVolumeCount
|
||||||
return dn
|
r.LinkChildNode(dn)
|
||||||
|
return dn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rack *Rack) ToMap() interface{}{
|
func (rack *Rack) ToMap() interface{} {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
m["Free"] = rack.FreeSpace()
|
m["Free"] = rack.FreeSpace()
|
||||||
var dns []interface{}
|
var dns []interface{}
|
||||||
for _, c := range rack.Children() {
|
for _, c := range rack.Children() {
|
||||||
dn := c.(*DataNode)
|
dn := c.(*DataNode)
|
||||||
dns = append(dns, dn.ToMap())
|
dns = append(dns, dn.ToMap())
|
||||||
}
|
}
|
||||||
m["DataNodes"] = dns
|
m["DataNodes"] = dns
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,22 +34,25 @@ func NewTopology(id string, dirname string, filename string, volumeSizeLimit uin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Topology) RandomlyReserveOneVolume() (bool, *DataNode, *storage.VolumeId) {
|
func (t *Topology) RandomlyReserveOneVolume() (bool, *DataNode, *storage.VolumeId) {
|
||||||
if t.FreeSpace()<=0 {
|
if t.FreeSpace() <= 0 {
|
||||||
return false, nil, nil
|
return false, nil, nil
|
||||||
}
|
}
|
||||||
vid := t.NextVolumeId()
|
vid := t.NextVolumeId()
|
||||||
ret, node := t.ReserveOneVolume(rand.Intn(t.FreeSpace()), vid)
|
ret, node := t.ReserveOneVolume(rand.Intn(t.FreeSpace()), vid)
|
||||||
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 {
|
||||||
|
|
Loading…
Reference in a new issue