Add ever_rebalanced property to RingBuilder

...to formalize an otherwise-unwritten contract and get
CooperativeRingBuilder using more "public" interfaces.

Change-Id: Ib6666728eabeff948bb53dff054a69bada47556e
This commit is contained in:
Tim Burke 2017-07-21 17:21:49 -07:00
parent 71ec83f414
commit c211141c27
2 changed files with 6 additions and 2 deletions

View File

@ -146,6 +146,10 @@ class RingBuilder(object):
def part_shift(self):
return 32 - self.part_power
@property
def ever_rebalanced(self):
return self._last_part_moves is not None
def _set_part_moved(self, part):
self._last_part_moves[part] = 0
byte, bit = divmod(part, 8)
@ -485,7 +489,7 @@ class RingBuilder(object):
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._last_part_moves = array('B', itertools.repeat(0, self.parts))
self._update_last_part_moves()

View File

@ -719,7 +719,7 @@ class CooperativeRingBuilder(RingBuilder):
:return: True if the partition can be moved, False otherwise.
"""
# 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))
def _update_last_part_moves(self):