Merge "Tighten the move-one-replica test"
This commit is contained in:
@@ -1064,8 +1064,6 @@ class RingBuilder(object):
|
|||||||
overweight_dev_replica.sort(
|
overweight_dev_replica.sort(
|
||||||
key=lambda dr: dr[0]['parts_wanted'])
|
key=lambda dr: dr[0]['parts_wanted'])
|
||||||
for dev, replica in overweight_dev_replica:
|
for dev, replica in overweight_dev_replica:
|
||||||
if (not self._can_part_move(part)):
|
|
||||||
break
|
|
||||||
if any(replica_plan[tier]['min'] <=
|
if any(replica_plan[tier]['min'] <=
|
||||||
replicas_at_tier[tier] <
|
replicas_at_tier[tier] <
|
||||||
replica_plan[tier]['max']
|
replica_plan[tier]['max']
|
||||||
@@ -1084,6 +1082,7 @@ class RingBuilder(object):
|
|||||||
for tier in dev['tiers']:
|
for tier in dev['tiers']:
|
||||||
replicas_at_tier[tier] -= 1
|
replicas_at_tier[tier] -= 1
|
||||||
self._set_part_moved(part)
|
self._set_part_moved(part)
|
||||||
|
break
|
||||||
|
|
||||||
def _gather_parts_for_balance(self, assign_parts, replica_plan):
|
def _gather_parts_for_balance(self, assign_parts, replica_plan):
|
||||||
"""
|
"""
|
||||||
@@ -1140,8 +1139,6 @@ class RingBuilder(object):
|
|||||||
overweight_dev_replica.sort(
|
overweight_dev_replica.sort(
|
||||||
key=lambda dr: dr[0]['parts_wanted'])
|
key=lambda dr: dr[0]['parts_wanted'])
|
||||||
for dev, replica in overweight_dev_replica:
|
for dev, replica in overweight_dev_replica:
|
||||||
if (not self._can_part_move(part)):
|
|
||||||
break
|
|
||||||
# this is the most overweight_device holding a replica of this
|
# this is the most overweight_device holding a replica of this
|
||||||
# part we don't know where it's going to end up - but we'll
|
# part we don't know where it's going to end up - but we'll
|
||||||
# pick it up and hope for the best.
|
# pick it up and hope for the best.
|
||||||
@@ -1153,6 +1150,7 @@ class RingBuilder(object):
|
|||||||
part, replica, dev['id'])
|
part, replica, dev['id'])
|
||||||
self._replica2part2dev[replica][part] = NONE_DEV
|
self._replica2part2dev[replica][part] = NONE_DEV
|
||||||
self._set_part_moved(part)
|
self._set_part_moved(part)
|
||||||
|
break
|
||||||
|
|
||||||
def _reassign_parts(self, reassign_parts, replica_plan):
|
def _reassign_parts(self, reassign_parts, replica_plan):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -758,22 +758,24 @@ class TestRingBuilder(unittest.TestCase):
|
|||||||
expected = defaultdict(int, {0: 256, 1: 256, 2: 86, 3: 85, 4: 85})
|
expected = defaultdict(int, {0: 256, 1: 256, 2: 86, 3: 85, 4: 85})
|
||||||
self.assertEqual(expected, self._partition_counts(rb, key='zone'))
|
self.assertEqual(expected, self._partition_counts(rb, key='zone'))
|
||||||
|
|
||||||
parts_with_moved_count = defaultdict(int)
|
zone_histogram = defaultdict(int)
|
||||||
for part in range(rb.parts):
|
for part in range(rb.parts):
|
||||||
zones = set()
|
zones = [
|
||||||
for replica in range(rb.replicas):
|
rb.devs[rb._replica2part2dev[replica][part]]['zone']
|
||||||
zones.add(rb.devs[rb._replica2part2dev[replica][part]]['zone'])
|
for replica in range(rb.replicas)]
|
||||||
moved_replicas = len(zones - {0, 1})
|
zone_histogram[tuple(sorted(zones))] += 1
|
||||||
parts_with_moved_count[moved_replicas] += 1
|
|
||||||
|
|
||||||
# We expect that every partition moved exactly one replica
|
# We expect that every partition moved exactly one replica
|
||||||
expected = {1: 256}
|
expected = {
|
||||||
self.assertEqual(parts_with_moved_count, expected)
|
(0, 1, 2): 86,
|
||||||
|
(0, 1, 3): 85,
|
||||||
|
(0, 1, 4): 85,
|
||||||
|
}
|
||||||
|
self.assertEqual(zone_histogram, expected)
|
||||||
|
|
||||||
# After rebalancing two more times, we expect that everything is in a
|
# After rebalancing two more times, we expect that everything is in a
|
||||||
# good state
|
# good state
|
||||||
rb.rebalance(seed=3)
|
rb.rebalance(seed=3)
|
||||||
rb.rebalance(seed=3)
|
|
||||||
|
|
||||||
self.assertEqual(0, rb.dispersion)
|
self.assertEqual(0, rb.dispersion)
|
||||||
# a balance of w/i a 1% isn't too bad for 3 replicas on 7
|
# a balance of w/i a 1% isn't too bad for 3 replicas on 7
|
||||||
|
|||||||
Reference in New Issue
Block a user