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

Simplify Cluster.computeMoves

Since we now have an actual type for describing the instance moves
(IMove), it's simpler to convert this into the move description/move
commands, rather than re-computing the move based on initial and final
nodes. This makes the shell commands computation and over-Luxi command
execution use the same method of computation.
parent eb2598ab
No related branches found
No related tags found
No related merge requests found
...@@ -565,8 +565,7 @@ tryReloc _ _ _ reqn _ = fail $ "Unsupported number of relocation \ ...@@ -565,8 +565,7 @@ tryReloc _ _ _ reqn _ = fail $ "Unsupported number of relocation \
-- | Given the original and final nodes, computes the relocation description. -- | Given the original and final nodes, computes the relocation description.
computeMoves :: Instance.Instance -- ^ The instance to be moved computeMoves :: Instance.Instance -- ^ The instance to be moved
-> String -- ^ The instance name -> String -- ^ The instance name
-> String -- ^ Original primary -> IMove -- ^ The move being performed
-> String -- ^ Original secondary
-> String -- ^ New primary -> String -- ^ New primary
-> String -- ^ New secondary -> String -- ^ New secondary
-> (String, [String]) -> (String, [String])
...@@ -574,27 +573,13 @@ computeMoves :: Instance.Instance -- ^ The instance to be moved ...@@ -574,27 +573,13 @@ computeMoves :: Instance.Instance -- ^ The instance to be moved
-- either @/f/@ for failover or @/r:name/@ for replace -- either @/f/@ for failover or @/r:name/@ for replace
-- secondary, while the command list holds gnt-instance -- secondary, while the command list holds gnt-instance
-- commands (without that prefix), e.g \"@failover instance1@\" -- commands (without that prefix), e.g \"@failover instance1@\"
computeMoves i inam a b c d computeMoves i inam mv c d =
-- same primary case mv of
| c == a = Failover -> ("f", [mig])
if d == b FailoverAndReplace _ -> (printf "f r:%s" d, [mig, rep d])
then {- Same sec??! -} ("-", []) ReplaceSecondary _ -> (printf "r:%s" d, [rep d])
else {- Change of secondary -} ReplaceAndFailover _ -> (printf "r:%s f" c, [rep c, mig])
(printf "r:%s" d, [rep d]) ReplacePrimary _ -> (printf "f r:%s f" c, [mig, rep c, mig])
-- failover and ...
| c == b =
if d == a
then {- that's all -} ("f", [mig])
else (printf "f r:%s" d, [mig, rep d])
-- ... and keep primary as secondary
| d == a =
(printf "r:%s f" c, [rep c, mig])
-- ... keep same secondary
| d == b =
(printf "f r:%s f" c, [mig, rep c, mig])
-- nothing in common -
| otherwise =
(printf "r:%s f r:%s" c d, [rep c, mig, rep d])
where morf = if Instance.running i then "migrate" else "failover" where morf = if Instance.running i then "migrate" else "failover"
mig = printf "%s -f %s" morf inam::String mig = printf "%s -f %s" morf inam::String
rep n = printf "replace-disks -n %s %s" n inam rep n = printf "replace-disks -n %s %s" n inam
...@@ -611,14 +596,14 @@ printSolutionLine :: Node.List -- ^ The node list ...@@ -611,14 +596,14 @@ printSolutionLine :: Node.List -- ^ The node list
printSolutionLine nl il nmlen imlen plc pos = printSolutionLine nl il nmlen imlen plc pos =
let let
pmlen = (2*nmlen + 1) pmlen = (2*nmlen + 1)
(i, p, s, _, c) = plc (i, p, s, mv, c) = plc
inst = Container.find i il inst = Container.find i il
inam = Instance.name inst inam = Instance.name inst
npri = Container.nameOf nl p npri = Container.nameOf nl p
nsec = Container.nameOf nl s nsec = Container.nameOf nl s
opri = Container.nameOf nl $ Instance.pNode inst opri = Container.nameOf nl $ Instance.pNode inst
osec = Container.nameOf nl $ Instance.sNode inst osec = Container.nameOf nl $ Instance.sNode inst
(moves, cmds) = computeMoves inst inam opri osec npri nsec (moves, cmds) = computeMoves inst inam mv npri nsec
ostr = printf "%s:%s" opri osec::String ostr = printf "%s:%s" opri osec::String
nstr = printf "%s:%s" npri nsec::String nstr = printf "%s:%s" npri nsec::String
in in
......
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