Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler: Add weighers for same shard (live-)migration #455

Draft
wants to merge 1 commit into
base: offline-migrate-gets-own-nova-check-type
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion nova/conf/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,70 @@

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect. Also note that this setting
only affects scheduling if the 'resize_same_shard' weigher is enabled.
only affects scheduling if the 'PreferSameShardOnResizeWeigher' weigher is
enabled.

Possible values:

* An integer or float value, where the value corresponds to the multipler
ratio for this weigher.

Related options:

* prefer_same_shard_live_migrate_weight_multiplier
* prefer_same_shard_migrate_weight_multiplier
"""),
cfg.FloatOpt("prefer_same_shard_live_migrate_weight_multiplier",
default=1.0,
help="""
Prefer scheduling on same-shard on live-migrate weight multiplier.

This option determines how strongly the previous shard should be preferred for
scheduling a live-migrating instance. A positive value will result in the
scheduler preferring the same shard that the instance was previously running
on. A negative value would prefer all other shards over the instance's previous
aggregate.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect. Also note that this setting
only affects scheduling if the 'PreferSameShardOnLiveMigrateWeigher' weigher is
enabled.

Possible values:

* An integer or float value, where the value corresponds to the multipler
ratio for this weigher.

Related options:

* prefer_same_shard_resize_weight_multiplier
* prefer_same_shard_migrate_weight_multiplier
"""),
cfg.FloatOpt("prefer_same_shard_migrate_weight_multiplier",
default=1.0,
help="""
Prefer scheduling on same-shard on migrate weight multiplier.

This option determines how strongly the previous shard should be preferred for
scheduling a offline migrating instance. A positive value will result in the
scheduler preferring the same shard that the instance was previously running
on. A negative value would prefer all other shards over the instance's previous
aggregate.

This option is only used by the FilterScheduler and its subclasses; if you use
a different scheduler, this option has no effect. Also note that this setting
only affects scheduling if the 'PreferSameShardOnLiveMigrateWeigher' weigher is
enabled.

Possible values:

* An integer or float value, where the value corresponds to the multipler
ratio for this weigher.

Related options:

* prefer_same_shard_resize_weight_multiplier
* prefer_same_shard_live_migrate_weight_multiplier
"""),
cfg.FloatOpt("hv_ram_class_weight_multiplier",
default=1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
"""
Prefer resize to same shard weigher. Resizing an instance gives the current
shard aggregate a higher priority.
Prefer same shard weigher. Resizing/live-migrating an instance gives the
current shard aggregate a higher priority.

This weigher ignores any instances which are:
* new instances (or unshelving)
* not resizing (a.k.a. migrating or rebuilding)
We split the functionality by action taken on the instance, so we can apply
different weights per action.
"""
from oslo_log import log as logging

Expand All @@ -31,21 +30,36 @@
CONF = nova.conf.CONF


class PreferSameShardOnResizeWeigher(weights.BaseHostWeigher):
class _SameShardWeigherBase(weights.BaseHostWeigher):
minval = 0
_SHARD_PREFIX = 'vc-'
_TYPE = None

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self._TYPE is None:
raise NotImplementedError(
'Children of _SameShardWeigherBase need to set _TYPE')

def weight_multiplier(self, host_state):
"""Override the weight multiplier."""
name = f"prefer_same_shard_{self._TYPE}_weight_multiplier"
return utils.get_weight_multiplier(
host_state, 'prefer_same_host_resize_weight_multiplier',
CONF.filter_scheduler.prefer_same_shard_resize_weight_multiplier)
host_state, name,
getattr(CONF.filter_scheduler, name))

def _weigh_object(self, host_state, request_spec):
"""Return 1 for about-to-be-resized instances where the shard is the
"""Return 1 for instances scheduled for _TYPE where the shard is the
instance's current shard. Return 0 otherwise.
"""
if not utils.request_is_resize(request_spec):
# check the type of the request matches the class' _TYPE
check_type_fn_name = f"request_is_{self._TYPE}"
check_type_fn = getattr(utils, check_type_fn_name, None)
if check_type_fn is None:
raise NotImplementedError(
f"nova.scheduler.utils.{check_type_fn_name}() does not exist "
f"for {self.__class__} with _TYPE {self._TYPE}")
if not check_type_fn(request_spec):
return 0.0

if utils.is_non_vmware_spec(request_spec):
Expand All @@ -70,3 +84,15 @@ def _weigh_object(self, host_state, request_spec):
if instance_host in host_shard_aggr.hosts:
return 1.0
return 0.0


class PreferSameShardOnResizeWeigher(_SameShardWeigherBase):
_TYPE = 'resize'


class PreferSameShardOnLiveMigrateWeigher(_SameShardWeigherBase):
_TYPE = 'live_migrate'


class PreferSameShardOnMigrateWeigher(_SameShardWeigherBase):
_TYPE = 'migrate'
150 changes: 0 additions & 150 deletions nova/tests/unit/scheduler/weights/test_weights_resize_same_shard.py

This file was deleted.

Loading