From 70db354eaef14c1c098cc205c5cc04f078e4db04 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 4 Jun 2009 15:32:59 +0200
Subject: [PATCH] Fix the ReplacePrimary instance move

During a replace-primary instance move, on the real cluster the instance
is temporarily started on the secondary, and as such we must check that
the secondary node can hold it for this duration. Currently the code
does not, and depending on cluster scoring it will put instances on such
'bad' secondaries (usually without enough memory).

This patch fixes this by adding/removing the instance as a primary on
the secondary node; and then using the result node as the new secondary.
(Since we're in a monad, we could have just tried the allocation and
dropped the result, but this is more clear).
---
 Ganeti/HTools/Cluster.hs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs
index 60d4ddd3c..4a30e3db2 100644
--- a/Ganeti/HTools/Cluster.hs
+++ b/Ganeti/HTools/Cluster.hs
@@ -467,8 +467,12 @@ applyMove nl inst (ReplacePrimary new_pdx) =
         int_p = Node.removePri old_p inst
         int_s = Node.removeSec old_s inst
         new_nl = do -- Maybe monad
+          -- check that the current secondary can host the instance
+          -- during the migration
+          tmp_s <- Node.addPri int_s inst
+          let tmp_s' = Node.removePri tmp_s inst
           new_p <- Node.addPri tgt_n inst
-          new_s <- Node.addSec int_s inst new_pdx
+          new_s <- Node.addSec tmp_s' inst new_pdx
           return $ Container.add new_pdx new_p $
                  Container.addTwo old_pdx int_p old_sdx new_s nl
     in (new_nl, Instance.setPri inst new_pdx, new_pdx, old_sdx)
-- 
GitLab