Commit a334d536 authored by Iustin Pop's avatar Iustin Pop
Browse files

Cleanup AllocSolution after AllocElement changes



Since we added the score to AllocElement, we don't need to wrap
AllocElement in yet another tuple, just to attach the cluster score. So
we simplify the AllocSolution type.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 7d3f4253
......@@ -81,7 +81,7 @@ import qualified Ganeti.OpCodes as OpCodes
-- * Types
-- | Allocation\/relocation solution.
type AllocSolution = ([FailMode], Int, [(Score, Node.AllocElement)])
type AllocSolution = ([FailMode], Int, [Node.AllocElement])
-- | The complete state for the balancing solution
data Table = Table Node.List Instance.List Score [Placement]
......@@ -538,15 +538,15 @@ concatAllocs (flst, cntok, sols) (OpFail reason) = (reason:flst, cntok, sols)
concatAllocs (flst, cntok, osols) (OpGood ns@(_, _, _, nscore)) =
let -- Choose the old or new solution, based on the cluster score
nsols = case osols of
[] -> [(nscore, ns)]
(oscore, _):[] ->
[] -> [ns]
(_, _, _, oscore):[] ->
if oscore < nscore
then osols
else [(nscore, ns)]
else [ns]
-- FIXME: here we simply concat to lists with more
-- than one element; we should instead abort, since
-- this is not a valid usage of this function
xs -> (nscore, ns):xs
xs -> ns:xs
nsuc = cntok + 1
-- Note: we force evaluation of nsols here in order to keep the
-- memory profile low - we know that we will need nsols for sure
......@@ -624,7 +624,7 @@ tryEvac nl il ex_ndx =
-- FIXME: hardcoded one node here
(fm, cs, aes) <- tryReloc nl' il idx 1 ex_ndx
case aes of
csol@(_, (nl'', _, _, _)):_ ->
csol@(nl'', _, _, _):_ ->
return (nl'', (fm, cs, csol:rsols))
_ -> fail $ "Can't evacuate instance " ++
Instance.name (Container.find idx il)
......@@ -649,7 +649,7 @@ iterateAlloc nl il newinst nreq ixes =
Ok (errs, _, sols3) ->
case sols3 of
[] -> Ok (collapseFailures errs, nl, il, ixes)
(_, (xnl, xi, _, _)):[] ->
(xnl, xi, _, _):[] ->
iterateAlloc xnl (Container.add newidx xi il)
newinst nreq $! (xi:ixes)
_ -> Bad "Internal error: multiple solutions for single\
......
......@@ -676,7 +676,7 @@ prop_ClusterAlloc_sane node inst =
Types.Ok (_, _, sols3) ->
case sols3 of
[] -> False
(_, (xnl, xi, _, cv)):[] ->
(xnl, xi, _, cv):[] ->
let il' = Container.add (Instance.idx xi) xi il
tbl = Cluster.Table xnl il' cv []
in not (canBalance tbl True False)
......@@ -716,7 +716,7 @@ prop_ClusterAllocEvac node inst =
Types.Ok (_, _, sols3) ->
case sols3 of
[] -> False
(_, (xnl, xi, _, _)):[] ->
(xnl, xi, _, _):[] ->
let sdx = Instance.sNode xi
il' = Container.add (Instance.idx xi) xi il
in case Cluster.tryEvac xnl il' [sdx] of
......
......@@ -4,7 +4,7 @@
{-
Copyright (C) 2009 Google Inc.
Copyright (C) 2009, 2010 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -51,7 +51,7 @@ processResults :: (Monad m) =>
-> m (String, Cluster.AllocSolution)
processResults _ (_, _, []) = fail "No valid allocation solutions"
processResults (Evacuate _) as@(fstats, successes, sols) =
let best = fst $ head sols
let (_, _, _, best) = head sols
tfails = length fstats
info = printf "for last allocation, successes %d, failures %d,\
\ best score: %.8f" successes tfails best::String
......@@ -59,7 +59,7 @@ processResults (Evacuate _) as@(fstats, successes, sols) =
processResults _ as@(fstats, successes, sols) =
case sols of
(best, (_, _, w, _)):[] ->
(_, _, w, best):[] ->
let tfails = length fstats
info = printf "successes %d, failures %d,\
\ best score: %.8f for node(s) %s"
......@@ -108,7 +108,7 @@ main = do
let (ok, info, rn) =
case sols of
Ok (ginfo, (_, _, sn)) -> (True, "Request successful: " ++ ginfo,
map snd sn)
sn)
Bad s -> (False, "Request failed: " ++ s, [])
resp = formatResponse ok info rq rn
putStrLn resp
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