From: Iustin Pop Date: Sun, 15 Feb 2009 13:48:39 +0000 (+0100) Subject: Simplify the checkInstanceMove function X-Git-Tag: htools-v0.0.4~1 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/9dc6023f3f671063125e3b6c5e632dfbca4af4aa Simplify the checkInstanceMove function This patch flattens the two folds into one, by simply building the whole list of moves instead of the double recursion (nodes and the each node's moves). This has no functional change, but it's much cleaner. --- diff --git a/src/Cluster.hs b/src/Cluster.hs index be811db..1cf5153 100644 --- a/src/Cluster.hs +++ b/src/Cluster.hs @@ -397,20 +397,13 @@ checkInstanceMove nodes_idx ini_tbl target = let opdx = Instance.pnode target osdx = Instance.snode target - nodes = filter (\idx -> idx /= opdx && idx /= osdx) - nodes_idx + nodes = filter (\idx -> idx /= opdx && idx /= osdx) nodes_idx aft_failover = checkSingleStep ini_tbl target ini_tbl Failover + all_moves = concatMap (\idx -> [ReplacePrimary idx, + ReplaceSecondary idx]) nodes in -- iterate over the possible nodes for this instance - foldl' - (\ accu_p new_idx -> - let - pmoves = [ReplacePrimary new_idx, - ReplaceSecondary new_idx] - in - foldl' -- while doing both possible moves - (checkSingleStep ini_tbl target) accu_p pmoves - ) aft_failover nodes + foldl' (checkSingleStep ini_tbl target) aft_failover all_moves -- | Compute the best next move. checkMove :: [Int] -- ^ Allowed target node indices