Commit e623dbe3 authored by Guido Trotter's avatar Guido Trotter
Browse files

Master candidate stats, return one more value



Other than returning the current number of candidates, and the number of
desired and possible candidates, we also return the maximum possible
number, even if greater than our desires. All callers for now ignore
this third value.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 34cb5617
...@@ -680,7 +680,7 @@ def _AdjustCandidatePool(lu): ...@@ -680,7 +680,7 @@ def _AdjustCandidatePool(lu):
", ".join(node.name for node in mod_list)) ", ".join(node.name for node in mod_list))
for name in mod_list: for name in mod_list:
lu.context.ReaddNode(name) lu.context.ReaddNode(name)
mc_now, mc_max = lu.cfg.GetMasterCandidateStats() mc_now, mc_max, _ = lu.cfg.GetMasterCandidateStats()
if mc_now > mc_max: if mc_now > mc_max:
lu.LogInfo("Note: more nodes are candidates (%d) than desired (%d)" % lu.LogInfo("Note: more nodes are candidates (%d) than desired (%d)" %
(mc_now, mc_max)) (mc_now, mc_max))
...@@ -2799,7 +2799,7 @@ class LUAddNode(LogicalUnit): ...@@ -2799,7 +2799,7 @@ class LUAddNode(LogicalUnit):
exceptions = [node] exceptions = [node]
else: else:
exceptions = [] exceptions = []
mc_now, mc_max = self.cfg.GetMasterCandidateStats(exceptions) mc_now, mc_max, _ = self.cfg.GetMasterCandidateStats(exceptions)
# the new node will increase mc_max with one, so: # the new node will increase mc_max with one, so:
mc_max = min(mc_max + 1, cp_size) mc_max = min(mc_max + 1, cp_size)
self.master_candidate = mc_now < mc_max self.master_candidate = mc_now < mc_max
...@@ -2973,7 +2973,7 @@ class LUSetNodeParams(LogicalUnit): ...@@ -2973,7 +2973,7 @@ class LUSetNodeParams(LogicalUnit):
if ((self.op.master_candidate == False or self.op.offline == True or if ((self.op.master_candidate == False or self.op.offline == True or
self.op.drained == True) and node.master_candidate): self.op.drained == True) and node.master_candidate):
cp_size = self.cfg.GetClusterInfo().candidate_pool_size cp_size = self.cfg.GetClusterInfo().candidate_pool_size
num_candidates, _ = self.cfg.GetMasterCandidateStats() num_candidates, _, _ = self.cfg.GetMasterCandidateStats()
if num_candidates <= cp_size: if num_candidates <= cp_size:
msg = ("Not enough master candidates (desired" msg = ("Not enough master candidates (desired"
" %d, new value will be %d)" % (cp_size, num_candidates-1)) " %d, new value will be %d)" % (cp_size, num_candidates-1))
......
...@@ -378,7 +378,7 @@ class ConfigWriter: ...@@ -378,7 +378,7 @@ class ConfigWriter:
result.append("Master node is not a master candidate") result.append("Master node is not a master candidate")
# master candidate checks # master candidate checks
mc_now, mc_max = self._UnlockedGetMasterCandidateStats() mc_now, mc_max, _ = self._UnlockedGetMasterCandidateStats()
if mc_now < mc_max: if mc_now < mc_max:
result.append("Not enough master candidates: actual %d, target %d" % result.append("Not enough master candidates: actual %d, target %d" %
(mc_now, mc_max)) (mc_now, mc_max))
...@@ -1015,10 +1015,10 @@ class ConfigWriter: ...@@ -1015,10 +1015,10 @@ class ConfigWriter:
@type exceptions: list @type exceptions: list
@param exceptions: if passed, list of nodes that should be ignored @param exceptions: if passed, list of nodes that should be ignored
@rtype: tuple @rtype: tuple
@return: tuple of (current, desired and possible) @return: tuple of (current, desired and possible, possible)
""" """
mc_now = mc_max = 0 mc_now = mc_should = mc_max = 0
for node in self._config_data.nodes.values(): for node in self._config_data.nodes.values():
if exceptions and node.name in exceptions: if exceptions and node.name in exceptions:
continue continue
...@@ -1026,8 +1026,8 @@ class ConfigWriter: ...@@ -1026,8 +1026,8 @@ class ConfigWriter:
mc_max += 1 mc_max += 1
if node.master_candidate: if node.master_candidate:
mc_now += 1 mc_now += 1
mc_max = min(mc_max, self._config_data.cluster.candidate_pool_size) mc_should = min(mc_max, self._config_data.cluster.candidate_pool_size)
return (mc_now, mc_max) return (mc_now, mc_should, mc_max)
@locking.ssynchronized(_config_lock, shared=1) @locking.ssynchronized(_config_lock, shared=1)
def GetMasterCandidateStats(self, exceptions=None): def GetMasterCandidateStats(self, exceptions=None):
...@@ -1051,7 +1051,7 @@ class ConfigWriter: ...@@ -1051,7 +1051,7 @@ class ConfigWriter:
@return: list with the adjusted nodes (L{objects.Node} instances) @return: list with the adjusted nodes (L{objects.Node} instances)
""" """
mc_now, mc_max = self._UnlockedGetMasterCandidateStats() mc_now, mc_max, _ = self._UnlockedGetMasterCandidateStats()
mod_list = [] mod_list = []
if mc_now < mc_max: if mc_now < mc_max:
node_list = self._config_data.nodes.keys() node_list = self._config_data.nodes.keys()
......
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