From c48bda0232482246874d9b9f6fe3e54e8195db2c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 1 Sep 2012 02:43:43 -0700 Subject: [PATCH] return the node during assigning free volume --- weed-fs/src/pkg/topology/node.go | 11 ++++++----- weed-fs/src/pkg/topology/topology.go | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/weed-fs/src/pkg/topology/node.go b/weed-fs/src/pkg/topology/node.go index ceea7731e..71c2ab914 100644 --- a/weed-fs/src/pkg/topology/node.go +++ b/weed-fs/src/pkg/topology/node.go @@ -28,11 +28,12 @@ func (n *Node) String() string { return string(n.Id) } -func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) bool { - ret := false +func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) (bool, *Node) { if n.children == nil { - return true + return true, n } + ret := false + var assignedNode *Node for _, node := range n.children { freeSpace := node.maxVolumeCount - node.activeVolumeCount - node.reservedVolumeCount 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 { r -= freeSpace } else { - ret = node.ReserveOneVolume(r, vid) + ret, assignedNode = node.ReserveOneVolume(r, vid) if ret { break } @@ -51,7 +52,7 @@ func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) bool { if ret { n.reservedVolumeCount++ } - return ret + return ret, assignedNode } func (n *Node) AddVolume(v *storage.VolumeInfo) { diff --git a/weed-fs/src/pkg/topology/topology.go b/weed-fs/src/pkg/topology/topology.go index 49ec944ad..04cd393c9 100644 --- a/weed-fs/src/pkg/topology/topology.go +++ b/weed-fs/src/pkg/topology/topology.go @@ -16,13 +16,14 @@ func NewTopology(id NodeId) *Topology{ 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 r := rand.Intn(slots) r = rand.Intn(slots) fmt.Println("slots:", slots, "random :", r) 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 {