From dcdce8782230c1e679165d16c2e064405b724227 Mon Sep 17 00:00:00 2001 From: Zhiteng Huang Date: Thu, 18 Sep 2014 15:02:55 -0700 Subject: [PATCH] Downgrade 'infinite' and 'unknown' capacity in weigher When FilterScheduler was first introduced into Cinder, drivers were required for the first time to report capacity. Some drivers preferred to report 'infinite' or 'unknown' capacity because they were doing thin-provisioning or the total capacity kept increasing. Now that we have better support for thin-provisioning and we do find unrealistic capacity couldn't do us any good in making optimal scheduling decision, because 'infinite' and 'unknown' would always have the highest weight when the weight multiplier is positive, which in most cases it is. Drivers are expected to avoid sending 'infinite' 'unknown' capacity anymore, instead, should report an actual real number for total/free capacity. This fix doesn't fix the driver, instead a small tweak is added to CapacityWeigher in order to downgrade those drivers who report 'infinite' or 'unknown' as free capacity. In particular, those who report 'infinite'/'unknown' free capacity will be adjusted to be the one has lowest weight, no matter in 'spreading' (weight multiplier>0) or 'stacking' (weight multiplier<0) mode. DocImpact Change-Id: Ied087386a1a2f43e6a77499a817d5c637ef448f6 Partial-bug: #1350638 --- cinder/scheduler/weights/capacity.py | 6 +++++- cinder/tests/scheduler/fakes.py | 4 ++-- cinder/tests/scheduler/test_capacity_weigher.py | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cinder/scheduler/weights/capacity.py b/cinder/scheduler/weights/capacity.py index 099c58d21..7ad78db83 100644 --- a/cinder/scheduler/weights/capacity.py +++ b/cinder/scheduler/weights/capacity.py @@ -67,7 +67,11 @@ class CapacityWeigher(weights.BaseHostWeigher): if free_space == 'infinite' or free_space == 'unknown': #(zhiteng) 'infinite' and 'unknown' are treated the same # here, for sorting purpose. - free = float('inf') + + # As a partial fix for bug #1350638, 'infinite' and 'unknown' are + # given the lowest weight to discourage driver from report such + # capacity anymore. + free = -1 if CONF.capacity_weight_multiplier > 0 else float('inf') else: free = math.floor(host_state.free_capacity_gb * (1 - reserved)) return free diff --git a/cinder/tests/scheduler/fakes.py b/cinder/tests/scheduler/fakes.py index 48c9cfc3a..1ce71c34a 100644 --- a/cinder/tests/scheduler/fakes.py +++ b/cinder/tests/scheduler/fakes.py @@ -57,8 +57,8 @@ class FakeHostManager(host_manager.HostManager): 'volume_backend_name': 'lvm4', 'timestamp': None, 'consistencygroup_support': True}, - 'host5': {'total_capacity_gb': 2048, - 'free_capacity_gb': 500, + 'host5': {'total_capacity_gb': 'infinite', + 'free_capacity_gb': 'unknown', 'allocated_capacity_gb': 1548, 'reserved_percentage': 5, 'timestamp': None}, diff --git a/cinder/tests/scheduler/test_capacity_weigher.py b/cinder/tests/scheduler/test_capacity_weigher.py index cc1df28e7..c28f384ae 100644 --- a/cinder/tests/scheduler/test_capacity_weigher.py +++ b/cinder/tests/scheduler/test_capacity_weigher.py @@ -59,6 +59,7 @@ class CapacityWeigherTestCase(test.TestCase): # host2: free_capacity_gb=300, free=300*(1-0.1) # host3: free_capacity_gb=512, free=256 # host4: free_capacity_gb=200, free=200*(1-0.05) + # host5: free_capacity_gb=unknown free=-1 # so, host1 should win: weighed_host = self._get_weighed_host(hostinfo_list) @@ -74,6 +75,7 @@ class CapacityWeigherTestCase(test.TestCase): # host2: free_capacity_gb=300, free=-300*(1-0.1) # host3: free_capacity_gb=512, free=-256 # host4: free_capacity_gb=200, free=-200*(1-0.05) + # host5: free_capacity_gb=unknown free=-float('inf') # so, host4 should win: weighed_host = self._get_weighed_host(hostinfo_list) @@ -89,6 +91,7 @@ class CapacityWeigherTestCase(test.TestCase): # host2: free_capacity_gb=300, free=300*(1-0.1)*2 # host3: free_capacity_gb=512, free=256*2 # host4: free_capacity_gb=200, free=200*(1-0.05)*2 + # host5: free_capacity_gb=unknown free=-2 # so, host1 should win: weighed_host = self._get_weighed_host(hostinfo_list) -- 2.45.2