Skip to content
Snippets Groups Projects
Commit 6ab3ce90 authored by Iustin Pop's avatar Iustin Pop
Browse files

Abstract the secondary evac into a separate function


This is generic enough (no longer depending on the replace type) that
it will be used for other replace modes too. So all we need to do is
to abstract it to a separate function (that can be called from
multiple branches) and to make the imove op_fn computation more
generic, instead of hard-coding it.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 53bddadd
No related branches found
No related tags found
No related merge requests found
...@@ -911,16 +911,7 @@ nodeEvacInstance nl il ChangePrimary ...@@ -911,16 +911,7 @@ nodeEvacInstance nl il ChangePrimary
nodeEvacInstance nl il ChangeSecondary nodeEvacInstance nl il ChangeSecondary
inst@(Instance.Instance {Instance.diskTemplate = DTDrbd8}) inst@(Instance.Instance {Instance.diskTemplate = DTDrbd8})
gdx avail_nodes = gdx avail_nodes =
do evacOneNodeOnly nl il inst gdx avail_nodes
let op_fn = ReplaceSecondary
(nl', inst', _, ndx) <- annotateResult "Can't find any good node" $
eitherToResult $
foldl' (evacDrbdSecondaryInner nl inst gdx op_fn)
(Left "no nodes available") avail_nodes
let idx = Instance.idx inst
il' = Container.add idx inst' il
ops = iMoveToJob nl' il' idx (op_fn ndx)
return (nl', il', ops)
-- The algorithm for ChangeAll is as follows: -- The algorithm for ChangeAll is as follows:
-- --
...@@ -961,6 +952,31 @@ nodeEvacInstance nl il ChangeAll ...@@ -961,6 +952,31 @@ nodeEvacInstance nl il ChangeAll
return (nl', il', ops) return (nl', il', ops)
-- | Generic function for changing one node of an instance.
--
-- This is similar to 'nodeEvacInstance' but will be used in a few of
-- its sub-patterns.
evacOneNodeOnly :: Node.List -- ^ The node list (cluster-wide)
-> Instance.List -- ^ Instance list (cluster-wide)
-> Instance.Instance -- ^ The instance to be evacuated
-> Gdx -- ^ The group we're targetting
-> [Ndx] -- ^ The list of available nodes
-- for allocation
-> Result (Node.List, Instance.List, [OpCodes.OpCode])
evacOneNodeOnly nl il inst gdx avail_nodes = do
op_fn <- case templateMirrorType (Instance.diskTemplate inst) of
MirrorNone -> Bad "Can't relocate/evacuate non-mirrored instances"
MirrorInternal -> Ok ReplaceSecondary
MirrorExternal -> Ok FailoverToAny
(nl', inst', _, ndx) <- annotateResult "Can't find any good node" $
eitherToResult $
foldl' (evacDrbdSecondaryInner nl inst gdx op_fn)
(Left "no nodes available") avail_nodes
let idx = Instance.idx inst
il' = Container.add idx inst' il
ops = iMoveToJob nl' il' idx (op_fn ndx)
return (nl', il', ops)
-- | Inner fold function for changing secondary of a DRBD instance. -- | Inner fold function for changing secondary of a DRBD instance.
-- --
-- The running solution is either a @Left String@, which means we -- The running solution is either a @Left String@, which means we
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment