Commit 1f4ae205 authored by Iustin Pop's avatar Iustin Pop
Browse files

htools: abstract and simplify a multigroup function



In the future, this 'split/associated instance idx list' functionality
will be used by other code, so let's move it to its own code.

The new method of computing the split also requires exporting one more
function from IntMap in Container.hs.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 8dda364e
......@@ -832,26 +832,10 @@ tryMGEvac :: (Monad m) =>
tryMGEvac _ nl il ex_ndx =
let ex_nodes = map (`Container.find` nl) ex_ndx
all_insts = nub . concatMap Node.sList $ ex_nodes
gni = splitCluster nl il
-- we run the instance index list through a couple of maps to
-- get finally to a structure of the type [(group index,
-- [instance indices])]
all_insts' = map (\idx ->
(instancePriGroup nl (Container.find idx il),
idx)) all_insts
all_insts'' = groupBy ((==) `on` fst) all_insts'
all_insts3 = map (\xs -> let (gdxs, idxs) = unzip xs
in (head gdxs, idxs)) all_insts''
all_insts' = associateIdxs all_insts $ splitCluster nl il
in do
-- that done, we now add the per-group nl/il to the tuple
all_insts4 <-
mapM (\(gdx, idxs) ->
case lookup gdx gni of
Nothing -> fail $ "Can't find group index " ++ show gdx
Just (gnl, gil) -> return (gdx, gnl, gil, idxs))
all_insts3
results <- mapM (\(_, gnl, gil, idxs) -> tryEvac gnl gil idxs ex_ndx)
all_insts4
results <- mapM (\(_, (gnl, gil, idxs)) -> tryEvac gnl gil idxs ex_ndx)
all_insts'
let sol = foldl' sumAllocs emptySolution results
return $ annotateSolution sol
......@@ -1110,3 +1094,12 @@ splitCluster nl il =
nodes' = zip nidxs nodes
instances = Container.filter ((`elem` nidxs) . Instance.pNode) il
in (guuid, (Container.fromList nodes', instances))) ngroups
-- | Split a global instance index map into per-group, and associate
-- it with the group/node/instance lists.
associateIdxs :: [Idx] -- ^ Instance indices to be split/associated
-> [(Gdx, (Node.List, Instance.List))] -- ^ Input groups
-> [(Gdx, (Node.List, Instance.List, [Idx]))] -- ^ Result
associateIdxs idxs =
map (\(gdx, (nl, il)) ->
(gdx, (nl, il, filter (`Container.member` il) idxs)))
......@@ -7,7 +7,7 @@ give the best performance for our workload.
{-
Copyright (C) 2009, 2010 Google Inc.
Copyright (C) 2009, 2010, 2011 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
......@@ -40,6 +40,7 @@ module Ganeti.HTools.Container
, IntMap.null
, find
, IntMap.findMax
, IntMap.member
-- * Update
, add
, addTwo
......
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