Fix a couple of bugs in handling offline instances
authorIustin Pop <iustin@google.com>
Thu, 5 Jan 2012 11:01:45 +0000 (12:01 +0100)
committerIustin Pop <iustin@google.com>
Fri, 13 Jan 2012 13:23:30 +0000 (14:23 +0100)
The addition of the offline state for instances has introduced a few
bugs related to their handling. The current code adds a helper
function for making the check whether an instances uses reserved
memory on the secondary (and uses it instead of just autoBalance),
and furthermore uses consistently the state for primary node
operations.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenĂ© Nussbaumer <rn@google.com>

htools/Ganeti/HTools/Instance.hs
htools/Ganeti/HTools/Node.hs

index b8e49ab..5acbbd3 100644 (file)
@@ -35,6 +35,7 @@ module Ganeti.HTools.Instance
   , instanceOffline
   , instanceNotOffline
   , instanceDown
+  , usesSecMem
   , applyIfOnline
   , setIdx
   , setName
@@ -114,6 +115,11 @@ instanceDown _                           = True
 applyIfOnline :: Instance -> (a -> a) -> a -> a
 applyIfOnline = applyIf . instanceNotOffline
 
+-- | Helper for determining whether an instance's memory needs to be
+-- taken into account for secondary memory reservation.
+usesSecMem :: Instance -> Bool
+usesSecMem inst = instanceNotOffline inst && autoBalance inst
+
 -- | Constant holding the local storage templates.
 --
 -- /Note:/ Currently Ganeti only exports node total/free disk space
index f01addb..740c0e9 100644 (file)
@@ -273,7 +273,7 @@ buildPeers :: Node -> Instance.List -> Node
 buildPeers t il =
   let mdata = map
               (\i_idx -> let inst = Container.find i_idx il
-                             mem = if Instance.autoBalance inst
+                             mem = if Instance.usesSecMem inst
                                      then Instance.mem inst
                                      else 0
                          in (Instance.pNode inst, mem))
@@ -293,7 +293,8 @@ setPri t inst = t { pList = Instance.idx inst:pList t
                   , utilLoad = utilLoad t `T.addUtil` Instance.util inst
                   , pTags = addTags (pTags t) (Instance.tags inst)
                   }
-  where new_count = uCpu t + Instance.vcpus inst
+  where new_count = Instance.applyIfOnline inst (+ Instance.vcpus inst)
+                    (uCpu t )
 
 -- | Assigns an instance to a node as secondary without other updates.
 setSec :: Node -> Instance.Instance -> Node
@@ -343,7 +344,7 @@ removeSec t inst =
                   else cur_dsk
       old_peers = peers t
       old_peem = P.find pnode old_peers
-      new_peem =  if Instance.autoBalance inst
+      new_peem =  if Instance.usesSecMem inst
                     then old_peem - Instance.mem inst
                     else old_peem
       new_peers = if new_peem > 0
@@ -423,8 +424,7 @@ addSecEx force t inst pdx =
       old_peers = peers t
       old_mem = fMem t
       new_dsk = fDsk t - Instance.dsk inst
-      secondary_needed_mem = if Instance.autoBalance inst &&
-                             not (Instance.instanceOffline inst)
+      secondary_needed_mem = if Instance.usesSecMem inst
                                then Instance.mem inst
                                else 0
       new_peem = P.find pdx old_peers + secondary_needed_mem