From a804261a8bed34977396a1146622a94c81f94548 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 14 Jan 2010 17:18:51 +0100 Subject: [PATCH] Move instance relocation test upper in the chain Currently we test each instance for relocation in checkMove; however, it is a little more clear if we pass only the relocatable instances to checkMove. The patch also slightly rewrites (indendation/style) the second half of the checkMove function. --- Ganeti/HTools/Cluster.hs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index ab5cbb4b5..625697c52 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -437,16 +437,13 @@ checkMove nodes_idx disk_moves ini_tbl victims = best_tbl = foldl' (\ step_tbl em -> - if Instance.sNode em == Node.noSecondary then step_tbl - else compareTables step_tbl $ - checkInstanceMove nodes_idx disk_moves ini_tbl em) + compareTables step_tbl $ + checkInstanceMove nodes_idx disk_moves ini_tbl em) ini_tbl victims Table _ _ _ best_plc = best_tbl - in - if length best_plc == length ini_plc then -- no advancement - ini_tbl - else - best_tbl + in if length best_plc == length ini_plc + then ini_tbl -- no advancement + else best_tbl -- | Check if we are allowed to go deeper in the balancing @@ -467,9 +464,11 @@ tryBalance :: Table -- ^ The starting table tryBalance ini_tbl disk_moves = let Table ini_nl ini_il ini_cv _ = ini_tbl all_inst = Container.elems ini_il + reloc_inst = filter (\e -> Instance.sNode e /= Node.noSecondary) + all_inst node_idx = map Node.idx . filter (not . Node.offline) $ Container.elems ini_nl - fin_tbl = checkMove node_idx disk_moves ini_tbl all_inst + fin_tbl = checkMove node_idx disk_moves ini_tbl reloc_inst (Table _ _ fin_cv _) = fin_tbl in if fin_cv < ini_cv -- GitLab