mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
return the node during assigning free volume
This commit is contained in:
parent
7a30a48027
commit
c48bda0232
|
@ -28,11 +28,12 @@ func (n *Node) String() string {
|
||||||
return string(n.Id)
|
return string(n.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) bool {
|
func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) (bool, *Node) {
|
||||||
ret := false
|
|
||||||
if n.children == nil {
|
if n.children == nil {
|
||||||
return true
|
return true, n
|
||||||
}
|
}
|
||||||
|
ret := false
|
||||||
|
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 - node.reservedVolumeCount
|
||||||
fmt.Println("r =", r, ", node =", node, ", freeSpace =", freeSpace)
|
fmt.Println("r =", r, ", node =", node, ", freeSpace =", freeSpace)
|
||||||
|
@ -42,7 +43,7 @@ func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) bool {
|
||||||
if r >= freeSpace {
|
if r >= freeSpace {
|
||||||
r -= freeSpace
|
r -= freeSpace
|
||||||
} else {
|
} else {
|
||||||
ret = node.ReserveOneVolume(r, vid)
|
ret, assignedNode = node.ReserveOneVolume(r, vid)
|
||||||
if ret {
|
if ret {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -51,7 +52,7 @@ func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) bool {
|
||||||
if ret {
|
if ret {
|
||||||
n.reservedVolumeCount++
|
n.reservedVolumeCount++
|
||||||
}
|
}
|
||||||
return ret
|
return ret, assignedNode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) AddVolume(v *storage.VolumeInfo) {
|
func (n *Node) AddVolume(v *storage.VolumeInfo) {
|
||||||
|
|
|
@ -16,13 +16,14 @@ func NewTopology(id NodeId) *Topology{
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Topology) RandomlyReserveOneVolume() (bool,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-t.Node.reservedVolumeCount
|
||||||
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)
|
||||||
vid := t.nextVolumeId()
|
vid := t.nextVolumeId()
|
||||||
return t.Node.ReserveOneVolume(r,vid), vid
|
ret, node := t.Node.ReserveOneVolume(r,vid)
|
||||||
|
return ret, node, vid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Topology) nextVolumeId() storage.VolumeId {
|
func (t *Topology) nextVolumeId() storage.VolumeId {
|
||||||
|
|
Loading…
Reference in a new issue