From d6c76bd58cd4d7c4d2a38841d2ba375f3e1976eb Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 24 Jan 2011 11:02:30 +0100
Subject: [PATCH] tryAlloc: restrict valid node pairs to same-group

This is a cheap way to make capacity calculation work well with
multi-group clusters.

There are two alternatives in implementing this:

- we can split the cluster into groups, run individual group
  allocation, and then try to recombine the groups; but this doesn't
  represent the allocation as it would happen in real life, when
  groups are not filled in succession, and would complicate TSPECS
  ordering
- or add this "hack" which does the allocation look at all node pairs
  (per group) at each step, which makes it correct from the point of
  view of ordering of allocations w.r.t. groups

For now, we take the second choice, with the future possibility of
revisiting the first one.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 Ganeti/HTools/Cluster.hs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs
index 48a0cc827..22be42a48 100644
--- a/Ganeti/HTools/Cluster.hs
+++ b/Ganeti/HTools/Cluster.hs
@@ -624,7 +624,8 @@ tryAlloc :: (Monad m) =>
 tryAlloc nl _ inst 2 =
     let all_nodes = getOnline nl
         all_pairs = liftM2 (,) all_nodes all_nodes
-        ok_pairs = filter (\(x, y) -> Node.idx x /= Node.idx y) all_pairs
+        ok_pairs = filter (\(x, y) -> Node.idx x /= Node.idx y &&
+                                      Node.group x == Node.group y) all_pairs
         sols = foldl' (\cstate (p, s) ->
                            concatAllocs cstate $ allocateOnPair nl inst p s
                       ) emptySolution ok_pairs
-- 
GitLab