Commit 5ad86777 authored by Iustin Pop's avatar Iustin Pop
Browse files

Split the balancing function in two parts

Currently in the balancing function we do two thing:

- take the decision where to do a new balancing round or not
- and actually computing the balancing round

This is not nice, as the two parts are conceptually separate, so this
patch splits the decision on whether to descend or not to a new
function.
parent 210ed839
......@@ -47,6 +47,7 @@ module Ganeti.HTools.Cluster
, printInsts
-- * Balacing functions
, checkMove
, doNextBalance
, tryBalance
, compCV
, printStats
......@@ -77,7 +78,6 @@ type AllocSolution = ([FailMode], Int, Maybe (Score, AllocElement))
-- | Allocation\/relocation element.
type AllocElement = (Node.List, Instance.Instance, [Node.Node])
-- | The complete state for the balancing solution
data Table = Table Node.List Instance.List Score [Placement]
deriving (Show)
......@@ -448,29 +448,32 @@ checkMove nodes_idx disk_moves ini_tbl victims =
else
best_tbl
-- | Check if we are allowed to go deeper in the balancing
doNextBalance :: Table -- ^ The starting table
-> Int -- ^ Remaining length
-> Score -- ^ Score at which to stop
-> Bool -- ^ The resulting table and commands
doNextBalance ini_tbl max_rounds min_score =
let Table _ _ ini_cv ini_plc = ini_tbl
ini_plc_len = length ini_plc
in (max_rounds < 0 || ini_plc_len < max_rounds) && ini_cv > min_score
-- | Run a balance move
tryBalance :: Table -- ^ The starting table
-> Int -- ^ Remaining length
-> Bool -- ^ Allow disk moves
-> Score -- ^ Score at which to stop
-> Maybe Table -- ^ The resulting table and commands
tryBalance ini_tbl max_rounds disk_moves min_score =
let Table ini_nl ini_il ini_cv ini_plc = ini_tbl
ini_plc_len = length ini_plc
allowed_next = (max_rounds < 0 || ini_plc_len < max_rounds) &&
ini_cv > min_score
tryBalance ini_tbl disk_moves =
let Table ini_nl ini_il ini_cv _ = ini_tbl
all_inst = Container.elems ini_il
node_idx = map Node.idx . filter (not . Node.offline) $
Container.elems ini_nl
fin_tbl = checkMove node_idx disk_moves ini_tbl all_inst
(Table _ _ fin_cv _) = fin_tbl
in
if allowed_next
then let all_inst = Container.elems ini_il
node_idx = map Node.idx . filter (not . Node.offline) $
Container.elems ini_nl
fin_tbl = checkMove node_idx disk_moves ini_tbl all_inst
(Table _ _ fin_cv _) = fin_tbl
in
if fin_cv < ini_cv
then Just fin_tbl -- this round made success, try deeper
else Nothing
if fin_cv < ini_cv
then Just fin_tbl -- this round made success, return the new table
else Nothing
-- * Allocation functions
......
......@@ -94,7 +94,10 @@ iterateDepth :: Cluster.Table -- ^ The starting table
iterateDepth ini_tbl max_rounds disk_moves nmlen imlen
cmd_strs oneline min_score =
let Cluster.Table ini_nl ini_il _ _ = ini_tbl
m_fin_tbl = Cluster.tryBalance ini_tbl max_rounds disk_moves min_score
allowed_next = Cluster.doNextBalance ini_tbl max_rounds min_score
m_fin_tbl = if allowed_next
then Cluster.tryBalance ini_tbl disk_moves
else Nothing
in
case m_fin_tbl of
Just fin_tbl ->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment