Revision d7339c99

b/htools/Ganeti/HTools/Cluster.hs
600 600
    map (\k -> (k, foldl' (\a e -> if e == k then a + 1 else a) 0 flst))
601 601
            [minBound..maxBound]
602 602

  
603
-- | Compares two Maybe AllocElement and chooses the besst score.
604
bestAllocElement :: Maybe Node.AllocElement
605
                 -> Maybe Node.AllocElement
606
                 -> Maybe Node.AllocElement
607
bestAllocElement a Nothing = a
608
bestAllocElement Nothing b = b
609
bestAllocElement a@(Just (_, _, _, ascore)) b@(Just (_, _, _, bscore)) =
610
    if ascore < bscore then a else b
611

  
603 612
-- | Update current Allocation solution and failure stats with new
604 613
-- elements.
605 614
concatAllocs :: AllocSolution -> OpResult Node.AllocElement -> AllocSolution
606 615
concatAllocs as (OpFail reason) = as { asFailures = reason : asFailures as }
607 616

  
608
concatAllocs as (OpGood ns@(_, _, _, nscore)) =
617
concatAllocs as (OpGood ns) =
609 618
    let -- Choose the old or new solution, based on the cluster score
610 619
        cntok = asAllocs as
611 620
        osols = asSolution as
612
        nsols = case osols of
613
                  Nothing -> Just ns
614
                  Just (_, _, _, oscore) ->
615
                      if oscore < nscore
616
                      then osols
617
                      else Just ns
621
        nsols = bestAllocElement osols (Just ns)
618 622
        nsuc = cntok + 1
619 623
    -- Note: we force evaluation of nsols here in order to keep the
620 624
    -- memory profile low - we know that we will need nsols for sure

Also available in: Unified diff