From 955d4b25d83f568962fc8854d491f769b067beaf Mon Sep 17 00:00:00 2001 From: tnextday Date: Mon, 4 Jan 2016 23:51:40 +0800 Subject: [PATCH] Node: add planned vloume count --- go/topology/node.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/go/topology/node.go b/go/topology/node.go index a8c5c0ded..655e496b1 100644 --- a/go/topology/node.go +++ b/go/topology/node.go @@ -19,11 +19,13 @@ type Node interface { UpAdjustMaxVolumeCountDelta(maxVolumeCountDelta int) UpAdjustVolumeCountDelta(volumeCountDelta int) UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int) + UpAdjustPlannedVolumeCountDelta(delta int) UpAdjustMaxVolumeId(vid storage.VolumeId) GetVolumeCount() int GetActiveVolumeCount() int GetMaxVolumeCount() int + GetPlannedVolumeCount() int GetMaxVolumeId() storage.VolumeId SetParent(Node) LinkChildNode(node Node) @@ -39,13 +41,14 @@ type Node interface { GetValue() interface{} //get reference to the topology,dc,rack,datanode } type NodeImpl struct { - id NodeId - volumeCount int - activeVolumeCount int - maxVolumeCount int - parent Node - children map[NodeId]Node - maxVolumeId storage.VolumeId + id NodeId + volumeCount int + activeVolumeCount int + maxVolumeCount int + plannedVolumeCount int + parent Node + children map[NodeId]Node + maxVolumeId storage.VolumeId //for rack, data center, topology nodeType string @@ -133,7 +136,7 @@ func (n *NodeImpl) Id() NodeId { return n.id } func (n *NodeImpl) FreeSpace() int { - return n.maxVolumeCount - n.volumeCount + return n.maxVolumeCount - n.volumeCount - n.plannedVolumeCount } func (n *NodeImpl) SetParent(node Node) { n.parent = node @@ -188,6 +191,14 @@ func (n *NodeImpl) UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta int) { n.parent.UpAdjustActiveVolumeCountDelta(activeVolumeCountDelta) } } + +func (n *NodeImpl) UpAdjustPlannedVolumeCountDelta(delta int) { //can be negative + n.plannedVolumeCount += delta + if n.parent != nil { + n.parent.UpAdjustPlannedVolumeCountDelta(delta) + } +} + func (n *NodeImpl) UpAdjustMaxVolumeId(vid storage.VolumeId) { //can be negative if n.maxVolumeId < vid { n.maxVolumeId = vid @@ -209,6 +220,10 @@ func (n *NodeImpl) GetMaxVolumeCount() int { return n.maxVolumeCount } +func (n *NodeImpl) GetPlannedVolumeCount() int { + return n.plannedVolumeCount +} + func (n *NodeImpl) LinkChildNode(node Node) { if n.children[node.Id()] == nil { n.children[node.Id()] = node