diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index d8e6de1865137932817d1278bca04491cddbaab4..b1deac3fa8ef7e76442c8c827ad6aed833dc5a4a 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -497,8 +497,10 @@ doNextBalance ini_tbl max_rounds min_score = tryBalance :: Table -- ^ The starting table -> Bool -- ^ Allow disk moves -> Bool -- ^ Only evacuate moves + -> Score -- ^ Min gain threshold + -> Score -- ^ Min gain -> Maybe Table -- ^ The resulting table and commands -tryBalance ini_tbl disk_moves evac_mode = +tryBalance ini_tbl disk_moves evac_mode mg_limit min_gain = let Table ini_nl ini_il ini_cv _ = ini_tbl all_inst = Container.elems ini_il all_inst' = if evac_mode @@ -514,7 +516,7 @@ tryBalance ini_tbl disk_moves evac_mode = fin_tbl = checkMove node_idx disk_moves ini_tbl reloc_inst (Table _ _ fin_cv _) = fin_tbl in - if fin_cv < ini_cv + if fin_cv < ini_cv && (ini_cv > mg_limit || ini_cv - fin_cv >= min_gain) then Just fin_tbl -- this round made success, return the new table else Nothing diff --git a/Ganeti/HTools/QC.hs b/Ganeti/HTools/QC.hs index 6cc36a85e8c7ef2b06e0e5521e3ec7051c6f3fc7..5f3b0a86b4301b4fe03a0e469b157cd87789b7dc 100644 --- a/Ganeti/HTools/QC.hs +++ b/Ganeti/HTools/QC.hs @@ -119,7 +119,7 @@ isNodeBig node size = Node.availDisk node > size * Types.unitDsk && Node.availCpu node > size * Types.unitCpu canBalance :: Cluster.Table -> Bool -> Bool -> Bool -canBalance tbl dm evac = isJust $ Cluster.tryBalance tbl dm evac +canBalance tbl dm evac = isJust $ Cluster.tryBalance tbl dm evac 0 0 -- * Arbitrary instances diff --git a/hbal.hs b/hbal.hs index 88c64dd932178c34e9b5021db74fd337e366b80f..de1cfe62a06d177e441841b1f2f39db766b2b979 100644 --- a/hbal.hs +++ b/hbal.hs @@ -70,6 +70,8 @@ options = , oMinScore , oMaxCpu , oMinDisk + , oMinGain + , oMinGainLim , oDiskMoves , oDynuFile , oExTags @@ -91,15 +93,18 @@ iterateDepth :: Cluster.Table -- ^ The starting table -> [MoveJob] -- ^ Current command list -> Bool -- ^ Whether to be silent -> Score -- ^ Score at which to stop + -> Score -- ^ Min gain limit + -> Score -- ^ Min score gain -> Bool -- ^ Enable evacuation mode -> IO (Cluster.Table, [MoveJob]) -- ^ The resulting table -- and commands iterateDepth ini_tbl max_rounds disk_moves nmlen imlen - cmd_strs oneline min_score evac_mode = + cmd_strs oneline min_score mg_limit min_gain evac_mode = let Cluster.Table ini_nl ini_il _ _ = ini_tbl allowed_next = Cluster.doNextBalance ini_tbl max_rounds min_score m_fin_tbl = if allowed_next then Cluster.tryBalance ini_tbl disk_moves evac_mode + mg_limit min_gain else Nothing in case m_fin_tbl of @@ -118,7 +123,7 @@ iterateDepth ini_tbl max_rounds disk_moves nmlen imlen hFlush stdout iterateDepth fin_tbl max_rounds disk_moves nmlen imlen upd_cmd_strs oneline min_score - evac_mode + mg_limit min_gain evac_mode Nothing -> return (ini_tbl, cmd_strs) -- | Formats the solution for the oneline display @@ -273,7 +278,9 @@ main = do (fin_tbl, cmd_strs) <- iterateDepth ini_tbl (optMaxLength opts) (optDiskMoves opts) - nmlen imlen [] oneline min_cv (optEvacMode opts) + nmlen imlen [] oneline min_cv + (optMinGainLim opts) (optMinGain opts) + (optEvacMode opts) let (Cluster.Table fin_nl fin_il fin_cv fin_plc) = fin_tbl ord_plc = reverse fin_plc sol_msg = if null fin_plc