Commit 55bd1414 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix a couple of bugs in handling offline instances



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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 9cd6c325
......@@ -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
......
......@@ -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
......
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