Merge "Support existing builders with None _last_part_moves"

This commit is contained in:
Zuul 2018-01-09 04:22:17 +00:00 committed by Gerrit Code Review
commit e7a99f9019
3 changed files with 20 additions and 3 deletions

View File

@ -945,7 +945,8 @@ swift-ring-builder <builder_file> rebalance [options]
balance_changed = (
abs(last_balance - balance) >= 1 or
(last_balance == MAX_BALANCE and balance == MAX_BALANCE))
dispersion_changed = abs(last_dispersion - dispersion) >= 1
dispersion_changed = last_dispersion is None or (
abs(last_dispersion - dispersion) >= 1)
if balance_changed or dispersion_changed:
be_cowardly = False

View File

@ -247,7 +247,11 @@ class RingBuilder(object):
self.version = builder.version
self._replica2part2dev = builder._replica2part2dev
self._last_part_moves_epoch = builder._last_part_moves_epoch
self._last_part_moves = builder._last_part_moves
if builder._last_part_moves is None:
self._last_part_moves = array(
'B', itertools.repeat(0, self.parts))
else:
self._last_part_moves = builder._last_part_moves
self._last_part_gather_start = builder._last_part_gather_start
self._remove_devs = builder._remove_devs
self._id = getattr(builder, '_id', None)
@ -263,7 +267,11 @@ class RingBuilder(object):
self.version = builder['version']
self._replica2part2dev = builder['_replica2part2dev']
self._last_part_moves_epoch = builder['_last_part_moves_epoch']
self._last_part_moves = builder['_last_part_moves']
if builder['_last_part_moves'] is None:
self._last_part_moves = array(
'B', itertools.repeat(0, self.parts))
else:
self._last_part_moves = builder['_last_part_moves']
self._last_part_gather_start = builder['_last_part_gather_start']
self._dispersion_graph = builder.get('_dispersion_graph', {})
self.dispersion = builder.get('dispersion')

View File

@ -2202,6 +2202,14 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
argv = ["", backup_file, "write_builder", "24"]
self.assertIsNone(ringbuilder.main(argv))
rb = RingBuilder.load(self.tmpfile + '.builder')
self.assertIsNotNone(rb._last_part_moves)
rb._last_part_moves = None
rb.save(self.tmpfile)
argv = ["", self.tmpfile + '.builder', "rebalance"]
self.assertSystemExit(EXIT_WARNING, ringbuilder.main, argv)
def test_warn_at_risk(self):
# check that warning is generated when rebalance does not achieve
# satisfactory balance