From 1760dd083d2987b7a5c956e0231297a02126d055 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 1 Sep 2012 10:51:07 -0700 Subject: [PATCH] remove reservedVolumeCount to simplify volume allocation logic --- weed-fs/src/pkg/topology/node.go | 12 +----------- weed-fs/src/pkg/topology/topology.go | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/weed-fs/src/pkg/topology/node.go b/weed-fs/src/pkg/topology/node.go index 71c2ab914..4352373cf 100644 --- a/weed-fs/src/pkg/topology/node.go +++ b/weed-fs/src/pkg/topology/node.go @@ -9,7 +9,6 @@ type NodeId string type Node struct { Id NodeId activeVolumeCount int - reservedVolumeCount int maxVolumeCount int parent *Node children map[NodeId]*Node @@ -35,7 +34,7 @@ func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) (bool, *Node) { ret := false var assignedNode *Node 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) if freeSpace <= 0 { continue @@ -49,9 +48,6 @@ func (n *Node) ReserveOneVolume(r int, vid storage.VolumeId) (bool, *Node) { } } } - if ret { - n.reservedVolumeCount++ - } return ret, assignedNode } @@ -61,9 +57,6 @@ func (n *Node) AddVolume(v *storage.VolumeInfo) { } n.activeVolumeCount++ fmt.Println(n.Id, "adds 1, volumeCount =", n.activeVolumeCount) - if n.reservedVolumeCount > 0 { //if reserved - n.reservedVolumeCount-- - } if n.parent != nil { n.parent.AddVolume(v) } @@ -83,7 +76,6 @@ func (n *Node) AddNode(node *Node) { if n.children[node.Id] == nil { n.children[node.Id] = node n.activeVolumeCount += node.activeVolumeCount - n.reservedVolumeCount += node.reservedVolumeCount n.maxVolumeCount += node.maxVolumeCount 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) n.activeVolumeCount -= node.activeVolumeCount n.maxVolumeCount -= node.maxVolumeCount - n.reservedVolumeCount -= node.reservedVolumeCount p := n.parent for p != nil { p.activeVolumeCount -= node.activeVolumeCount p.maxVolumeCount -= node.maxVolumeCount - p.reservedVolumeCount -= node.reservedVolumeCount p = p.parent } fmt.Println(n.Id, "removes", node.Id, "volumeCount =", n.activeVolumeCount) diff --git a/weed-fs/src/pkg/topology/topology.go b/weed-fs/src/pkg/topology/topology.go index 04cd393c9..846d4896e 100644 --- a/weed-fs/src/pkg/topology/topology.go +++ b/weed-fs/src/pkg/topology/topology.go @@ -17,7 +17,7 @@ func NewTopology(id NodeId) *Topology{ } 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) fmt.Println("slots:", slots, "random :", r)