From 40d4eba06cd66f3ddc12f41f09393c1a131c06dd Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sat, 21 Mar 2009 00:26:00 +0100 Subject: [PATCH] Restrict move list based on offline node status This patch changes the Cluster.checkInstanceMove function to restrict the target move list based on which nodes are online. --- Ganeti/HTools/Cluster.hs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index c6f8e6c2f..72ab0ffdb 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -431,6 +431,21 @@ checkSingleStep ini_tbl target cur_tbl move = in compareTables cur_tbl upd_tbl +-- | Given the status of the current secondary as a valid new node +-- and the current candidate target node, +-- generate the possible moves for a instance. +possibleMoves :: Bool -> Int -> [IMove] +possibleMoves True tdx = + [ReplaceSecondary tdx, + ReplaceAndFailover tdx, + ReplacePrimary tdx, + FailoverAndReplace tdx] + +possibleMoves False tdx = + [ReplaceSecondary tdx, + ReplaceAndFailover tdx] + +-- | Compute the best move for a given instance. checkInstanceMove :: [Int] -- Allowed target node indices -> Table -- Original table -> Instance.Instance -- Instance to move @@ -440,11 +455,11 @@ checkInstanceMove nodes_idx ini_tbl target = opdx = Instance.pnode target osdx = Instance.snode target nodes = filter (\idx -> idx /= opdx && idx /= osdx) nodes_idx - aft_failover = checkSingleStep ini_tbl target ini_tbl Failover - all_moves = concatMap (\idx -> [ReplacePrimary idx, - ReplaceSecondary idx, - ReplaceAndFailover idx, - FailoverAndReplace idx]) nodes + use_secondary = elem osdx nodes_idx + aft_failover = if use_secondary -- if allowed to failover + then checkSingleStep ini_tbl target ini_tbl Failover + else ini_tbl + all_moves = concatMap (possibleMoves use_secondary) nodes in -- iterate over the possible nodes for this instance foldl' (checkSingleStep ini_tbl target) aft_failover all_moves -- GitLab