mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
remove reservedVolumeCount to simplify volume allocation logic
This commit is contained in:
parent
c48bda0232
commit
1760dd083d
|
@ -9,7 +9,6 @@ type NodeId string
|
||||||
type Node struct {
|
type Node struct {
|
||||||
Id NodeId
|
Id NodeId
|
||||||
activeVolumeCount int
|
activeVolumeCount int
|
||||||
reservedVolumeCount int
|
|
||||||
maxVolumeCount int
|
maxVolumeCount int
|
||||||
parent *Node
|
parent *Node
|
||||||
children map[NodeId]*Node
|
children map[NodeId]*Node
|
||||||
|
@ -35,7 +34,7 @@ func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) (bool, *Node) {
|
||||||
ret := false
|
ret := false
|
||||||
var assignedNode *Node
|
var assignedNode *Node
|
||||||
for _, node := range n.children {
|
for _, node := range n.children {
|
||||||
freeSpace := node.maxVolumeCount - node.activeVolumeCount - node.reservedVolumeCount
|
freeSpace := node.maxVolumeCount - node.activeVolumeCount
|
||||||
fmt.Println("r =", r, ", node =", node, ", freeSpace =", freeSpace)
|
fmt.Println("r =", r, ", node =", node, ", freeSpace =", freeSpace)
|
||||||
if freeSpace <= 0 {
|
if freeSpace <= 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -49,9 +48,6 @@ func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) (bool, *Node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ret {
|
|
||||||
n.reservedVolumeCount++
|
|
||||||
}
|
|
||||||
return ret, assignedNode
|
return ret, assignedNode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,9 +57,6 @@ func (n *Node) AddVolume(v *storage.VolumeInfo) {
|
||||||
}
|
}
|
||||||
n.activeVolumeCount++
|
n.activeVolumeCount++
|
||||||
fmt.Println(n.Id, "adds 1, volumeCount =", n.activeVolumeCount)
|
fmt.Println(n.Id, "adds 1, volumeCount =", n.activeVolumeCount)
|
||||||
if n.reservedVolumeCount > 0 { //if reserved
|
|
||||||
n.reservedVolumeCount--
|
|
||||||
}
|
|
||||||
if n.parent != nil {
|
if n.parent != nil {
|
||||||
n.parent.AddVolume(v)
|
n.parent.AddVolume(v)
|
||||||
}
|
}
|
||||||
|
@ -83,7 +76,6 @@ func (n *Node) AddNode(node *Node) {
|
||||||
if n.children[node.Id] == nil {
|
if n.children[node.Id] == nil {
|
||||||
n.children[node.Id] = node
|
n.children[node.Id] = node
|
||||||
n.activeVolumeCount += node.activeVolumeCount
|
n.activeVolumeCount += node.activeVolumeCount
|
||||||
n.reservedVolumeCount += node.reservedVolumeCount
|
|
||||||
n.maxVolumeCount += node.maxVolumeCount
|
n.maxVolumeCount += node.maxVolumeCount
|
||||||
fmt.Println(n.Id, "adds", node.Id, "volumeCount =", n.activeVolumeCount)
|
fmt.Println(n.Id, "adds", node.Id, "volumeCount =", n.activeVolumeCount)
|
||||||
}
|
}
|
||||||
|
@ -95,12 +87,10 @@ func (n *Node) RemoveNode(nodeId NodeId) {
|
||||||
delete(n.children, node.Id)
|
delete(n.children, node.Id)
|
||||||
n.activeVolumeCount -= node.activeVolumeCount
|
n.activeVolumeCount -= node.activeVolumeCount
|
||||||
n.maxVolumeCount -= node.maxVolumeCount
|
n.maxVolumeCount -= node.maxVolumeCount
|
||||||
n.reservedVolumeCount -= node.reservedVolumeCount
|
|
||||||
p := n.parent
|
p := n.parent
|
||||||
for p != nil {
|
for p != nil {
|
||||||
p.activeVolumeCount -= node.activeVolumeCount
|
p.activeVolumeCount -= node.activeVolumeCount
|
||||||
p.maxVolumeCount -= node.maxVolumeCount
|
p.maxVolumeCount -= node.maxVolumeCount
|
||||||
p.reservedVolumeCount -= node.reservedVolumeCount
|
|
||||||
p = p.parent
|
p = p.parent
|
||||||
}
|
}
|
||||||
fmt.Println(n.Id, "removes", node.Id, "volumeCount =", n.activeVolumeCount)
|
fmt.Println(n.Id, "removes", node.Id, "volumeCount =", n.activeVolumeCount)
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewTopology(id NodeId) *Topology{
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Topology) RandomlyReserveOneVolume() (bool, *Node, storage.VolumeId) {
|
func (t *Topology) RandomlyReserveOneVolume() (bool, *Node, storage.VolumeId) {
|
||||||
slots := t.Node.maxVolumeCount-t.Node.activeVolumeCount-t.Node.reservedVolumeCount
|
slots := t.Node.maxVolumeCount-t.Node.activeVolumeCount
|
||||||
r := rand.Intn(slots)
|
r := rand.Intn(slots)
|
||||||
r = rand.Intn(slots)
|
r = rand.Intn(slots)
|
||||||
fmt.Println("slots:", slots, "random :", r)
|
fmt.Println("slots:", slots, "random :", r)
|
||||||
|
|
Loading…
Reference in a new issue