Merge "Add ever_rebalanced property to RingBuilder"

This commit is contained in:
Jenkins 2017-07-26 22:07:02 +00:00 committed by Gerrit Code Review
commit 4ac456882e
2 changed files with 6 additions and 2 deletions

View File

@ -146,6 +146,10 @@ class RingBuilder(object):
def part_shift(self): def part_shift(self):
return 32 - self.part_power return 32 - self.part_power
@property
def ever_rebalanced(self):
return self._last_part_moves is not None
def _set_part_moved(self, part): def _set_part_moved(self, part):
self._last_part_moves[part] = 0 self._last_part_moves[part] = 0
byte, bit = divmod(part, 8) byte, bit = divmod(part, 8)
@ -485,7 +489,7 @@ class RingBuilder(object):
old_replica2part2dev = copy.deepcopy(self._replica2part2dev) old_replica2part2dev = copy.deepcopy(self._replica2part2dev)
if self._last_part_moves is None: if not self.ever_rebalanced:
self.logger.debug("New builder; performing initial balance") self.logger.debug("New builder; performing initial balance")
self._last_part_moves = array('B', itertools.repeat(0, self.parts)) self._last_part_moves = array('B', itertools.repeat(0, self.parts))
self._update_last_part_moves() self._update_last_part_moves()

View File

@ -719,7 +719,7 @@ class CooperativeRingBuilder(RingBuilder):
:return: True if the partition can be moved, False otherwise. :return: True if the partition can be moved, False otherwise.
""" """
# called by parent_builder - now forward to the superclass # called by parent_builder - now forward to the superclass
return (not self._last_part_moves or return (not self.ever_rebalanced or
super(CooperativeRingBuilder, self)._can_part_move(part)) super(CooperativeRingBuilder, self)._can_part_move(part))
def _update_last_part_moves(self): def _update_last_part_moves(self):