Repository navigation
mgr/cephadm: make scheduling make sense #34633
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
Changes from all commits
b08fd9d
b7bb389
2d3a5a2
eae4707
beb80c0
671f03b
0747452
f873d49
b307021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| Cephadm Scheduler | ||
| ================= | ||
|
|
||
| Cephadm uses a declarative state to define the layout of the cluster. This | ||
| state consists of a list of service specificatins containing placement | ||
| specifications (See :ref:`orchestrator-cli-service-spec` ). | ||
|
|
||
| Cephadm constantly compares list of actually running daemons in the cluster | ||
| with the desired service specifications and will either add or remove new | ||
| daemons. | ||
|
|
||
| First, cephadm will select a list of candidate hosts. It first looks for | ||
| explicit host names and will select those. In case there are no explicit hosts | ||
| defined, cephadm looks for a label specification. If there is no label defined | ||
| in the specification, cephadm will select hosts based on a host pattern. If | ||
| there is no pattern defined, cepham will finally select all known hosts as | ||
| candidates. | ||
|
|
||
| Then, cephadm will consider existing daemons of this servics and will try to | ||
| avoid moving any daemons. | ||
|
|
||
| Cephadm supports the deployment of a specific amount of services. Let's | ||
| consider a service specification like so: | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| service_type: mds | ||
| service_name: myfs | ||
| placement: | ||
| count: 3 | ||
| label: myfs | ||
|
|
||
| This instructs cephadm to deploy three daemons on hosts labeld with | ||
| ``myfs`` across the cluster. | ||
|
|
||
| Then, in case there are less than three daemons deployed on the candidate | ||
| hosts, cephadm will then then randomly choose hosts for deploying new daemons. | ||
|
|
||
| In case there are more than three daemons deployed, cephadm will remove | ||
| existing daemons. | ||
|
|
||
| Finally, cephadm will remove daemons on hosts that are outside of the list of | ||
| candidate hosts. | ||
|
|
||
| However, there is a special cases that cephadm needs to consider. | ||
|
|
||
| In case the are fewer hosts selected by the placement specification than | ||
| demanded by ``count``, cephadm will only deploy on selected hosts. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,4 @@ versions of Ceph. | |
| Client Setup <client-setup> | ||
| DriveGroups <drivegroups> | ||
| troubleshooting | ||
| concepts | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import logging | ||
| from typing import TYPE_CHECKING, Iterator | ||
|
|
||
| from ceph.deployment.service_spec import PlacementSpec, ServiceSpec, HostPlacementSpec | ||
| from cephadm.schedule import HostAssignment | ||
|
|
||
| from orchestrator import OrchestratorError | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .module import CephadmOrchestrator | ||
|
|
||
| LAST_MIGRATION = 1 | ||
|
sebastian-philipp marked this conversation as resolved.
Resolved
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Migrations: | ||
| def __init__(self, mgr: "CephadmOrchestrator"): | ||
| self.mgr = mgr | ||
|
|
||
| # Why having a global counter, instead of spec versions? | ||
| # | ||
| # for the first migration: | ||
| # The specs don't change in (this) migration. but the scheduler here. | ||
| # Adding the version to the specs at this time just felt wrong to me. | ||
| # | ||
| # And the specs are only another part of cephadm which needs potential upgrades. | ||
| # We have the cache, the inventory, the config store, the upgrade (imagine changing the | ||
| # upgrade code, while an old upgrade is still in progress), naming of daemons, | ||
| # fs-layout of the daemons, etc. | ||
| if self.mgr.migration_current is None: | ||
| self.set(0) | ||
|
|
||
| # for some migrations, we don't need to do anything except for | ||
| # setting migration_current = 1. | ||
| # let's try to shortcut things here. | ||
| self.migrate() | ||
|
sebastian-philipp marked this conversation as resolved.
Resolved
|
||
|
|
||
| def set(self, val): | ||
| self.mgr.set_module_option('migration_current', val) | ||
| self.mgr.migration_current = val | ||
|
|
||
| def is_migration_ongoing(self): | ||
| return self.mgr.migration_current != LAST_MIGRATION | ||
|
|
||
| def verify_no_migration(self): | ||
| if self.is_migration_ongoing(): | ||
| # this is raised in module.serve() | ||
| raise OrchestratorError("cephadm migration still ongoing. Please wait, until the migration is complete.") | ||
|
sebastian-philipp marked this conversation as resolved.
Resolved
|
||
|
|
||
| def migrate(self): | ||
| if self.mgr.migration_current == 0: | ||
| if self.migrate_0_1(): | ||
| self.set(1) | ||
|
|
||
| def migrate_0_1(self) -> bool: | ||
| """ | ||
| Migration 0 -> 1 | ||
| New scheduler that takes PlacementSpec as the bound and not as recommendation. | ||
|
sebastian-philipp marked this conversation as resolved.
Resolved
|
||
| I.e. the new scheduler won't suggest any new placements outside of the hosts | ||
| specified by label etc. | ||
|
|
||
| Which means, we have to make sure, we're not removing any daemons directly after | ||
| upgrading to the new scheduler. | ||
|
|
||
| There is a potential race here: | ||
| 1. user updates his spec to remove daemons | ||
| 2. mgr gets upgraded to new scheduler, before the old scheduler removed the daemon | ||
| 3. now, we're converting the spec to explicit placement, thus reverting (1.) | ||
| I think this is ok. | ||
| """ | ||
|
|
||
| def interesting_specs() -> Iterator[ServiceSpec]: | ||
| for s in self.mgr.spec_store.specs.values(): | ||
| if s.unmanaged: | ||
| continue | ||
| p = s.placement | ||
| if p is None: | ||
| continue | ||
| if p.count is None: | ||
| continue | ||
| if not p.hosts and not p.host_pattern and not p.label: | ||
| continue | ||
| yield s | ||
|
|
||
| def convert_to_explicit(spec: ServiceSpec) -> None: | ||
| placements = HostAssignment( | ||
| spec=spec, | ||
| get_hosts_func=self.mgr._get_hosts, | ||
| get_daemons_func=self.mgr.cache.get_daemons_by_service | ||
| ).place() | ||
|
|
||
| existing_daemons = self.mgr.cache.get_daemons_by_service(spec.service_name()) | ||
|
|
||
| # We have to migrate, only if the new scheduler would remove daemons | ||
|
jschmid1 marked this conversation as resolved.
Resolved
|
||
| if len(placements) >= len(existing_daemons): | ||
| return | ||
|
|
||
| old_hosts = {h.hostname: h for h in spec.placement.hosts} | ||
| new_hosts = [ | ||
| old_hosts[d.hostname] if d.hostname in old_hosts else HostPlacementSpec(hostname=d.hostname, network='', name='') | ||
| for d in existing_daemons | ||
| ] | ||
|
|
||
| new_placement = PlacementSpec( | ||
| hosts=new_hosts, | ||
| count=spec.placement.count | ||
| ) | ||
|
|
||
| new_spec = ServiceSpec.from_json(spec.to_json()) | ||
| new_spec.placement = new_placement | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can also see an issue where a user would apply a cluster.yaml only when changing a single service. Since we converted the placement_glob(or pattern) to an explicit placement spec, they probably have to export and overwrite their existing cluster.yaml. I think this should be recommended somehow.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, that's a big problem but I didn't have a better answer.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having previews for all services would be a first step I think.. If placements would be changed completely we could atleast raise a warning before applying it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both schedulers behave very similar when it comes to assigning hosts. It's just the old assigned more hosts than the new one.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still struggling with this concept, but I suppose it's similar to k8s
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. but what's the alternative? what if the user wrongly created a placement like service_type: mon
placement:
label: mymons
count=5but only a single host was labled as |
||
|
|
||
| logger.info(f"Migrating {spec.one_line_str()} to explicit placement") | ||
|
|
||
| self.mgr.spec_store.save(new_spec) | ||
|
|
||
| specs = list(interesting_specs()) | ||
| if not specs: | ||
| return True # nothing to do. shortcut | ||
|
|
||
| if not self.mgr.cache.daemon_cache_filled(): | ||
| logger.info("Unable to migrate yet. Daemon Cache still incomplete.") | ||
| return False | ||
|
|
||
| for spec in specs: | ||
| convert_to_explicit(spec) | ||
|
|
||
| return True | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from . import remotes | ||||||||||||||||||||||||||||
| from . import utils | ||||||||||||||||||||||||||||
| from .migrations import Migrations | ||||||||||||||||||||||||||||
| from .services.cephadmservice import MonService, MgrService, MdsService, RgwService, \ | ||||||||||||||||||||||||||||
| RbdMirrorService, CrashService, CephadmService | ||||||||||||||||||||||||||||
| from .services.iscsi import IscsiService | ||||||||||||||||||||||||||||
|
|
@@ -258,6 +259,13 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): | |||||||||||||||||||||||||||
| 'default': '/etc/prometheus/ceph/ceph_default_alerts.yml', | ||||||||||||||||||||||||||||
| 'desc': 'location of alerts to include in prometheus deployments', | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| 'name': 'migration_current', | ||||||||||||||||||||||||||||
| 'type': 'int', | ||||||||||||||||||||||||||||
| 'default': None, | ||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm. When looking at the code: ceph/src/pybind/mgr/mgr_module.py Lines 643 to 655 in 11ddc9c
having a default that is arbitrary does seems to work find. Having the dashboard treat the values differently than the mgr_module.py seems odd to me.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||
| 'desc': 'internal - do not modify', | ||||||||||||||||||||||||||||
| # used to track track spec and other data migrations. | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def __init__(self, *args, **kwargs): | ||||||||||||||||||||||||||||
|
|
@@ -290,6 +298,7 @@ def __init__(self, *args, **kwargs): | |||||||||||||||||||||||||||
| self.warn_on_failed_host_check = True | ||||||||||||||||||||||||||||
| self.allow_ptrace = False | ||||||||||||||||||||||||||||
| self.prometheus_alerts_path = '' | ||||||||||||||||||||||||||||
| self.migration_current = None | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self._cons = {} # type: Dict[str, Tuple[remoto.backends.BaseConnection,remoto.backends.LegacyModuleExecute]] | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -335,6 +344,8 @@ def __init__(self, *args, **kwargs): | |||||||||||||||||||||||||||
| # in-memory only. | ||||||||||||||||||||||||||||
| self.offline_hosts: Set[str] = set() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self.migration = Migrations(self) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # services: | ||||||||||||||||||||||||||||
| self.osd_service = OSDService(self) | ||||||||||||||||||||||||||||
| self.nfs_service = NFSService(self) | ||||||||||||||||||||||||||||
|
|
@@ -481,56 +492,8 @@ def serve(self): | |||||||||||||||||||||||||||
| while self.run: | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # refresh daemons | ||||||||||||||||||||||||||||
| self.log.debug('refreshing hosts') | ||||||||||||||||||||||||||||
| bad_hosts = [] | ||||||||||||||||||||||||||||
| failures = [] | ||||||||||||||||||||||||||||
| for host in self.cache.get_hosts(): | ||||||||||||||||||||||||||||
| if self.cache.host_needs_check(host): | ||||||||||||||||||||||||||||
| r = self._check_host(host) | ||||||||||||||||||||||||||||
| if r is not None: | ||||||||||||||||||||||||||||
| bad_hosts.append(r) | ||||||||||||||||||||||||||||
| if self.cache.host_needs_daemon_refresh(host): | ||||||||||||||||||||||||||||
| self.log.debug('refreshing %s daemons' % host) | ||||||||||||||||||||||||||||
| r = self._refresh_host_daemons(host) | ||||||||||||||||||||||||||||
| if r: | ||||||||||||||||||||||||||||
| failures.append(r) | ||||||||||||||||||||||||||||
| if self.cache.host_needs_device_refresh(host): | ||||||||||||||||||||||||||||
| self.log.debug('refreshing %s devices' % host) | ||||||||||||||||||||||||||||
| r = self._refresh_host_devices(host) | ||||||||||||||||||||||||||||
| if r: | ||||||||||||||||||||||||||||
| failures.append(r) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if self.cache.host_needs_osdspec_preview_refresh(host): | ||||||||||||||||||||||||||||
| self.log.debug(f"refreshing OSDSpec previews for {host}") | ||||||||||||||||||||||||||||
| r = self._refresh_host_osdspec_previews(host) | ||||||||||||||||||||||||||||
| if r: | ||||||||||||||||||||||||||||
| failures.append(r) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| health_changed = False | ||||||||||||||||||||||||||||
| if 'CEPHADM_HOST_CHECK_FAILED' in self.health_checks: | ||||||||||||||||||||||||||||
| del self.health_checks['CEPHADM_HOST_CHECK_FAILED'] | ||||||||||||||||||||||||||||
| health_changed = True | ||||||||||||||||||||||||||||
| if bad_hosts: | ||||||||||||||||||||||||||||
| self.health_checks['CEPHADM_HOST_CHECK_FAILED'] = { | ||||||||||||||||||||||||||||
| 'severity': 'warning', | ||||||||||||||||||||||||||||
| 'summary': '%d hosts fail cephadm check' % len(bad_hosts), | ||||||||||||||||||||||||||||
| 'count': len(bad_hosts), | ||||||||||||||||||||||||||||
| 'detail': bad_hosts, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| health_changed = True | ||||||||||||||||||||||||||||
| if failures: | ||||||||||||||||||||||||||||
| self.health_checks['CEPHADM_REFRESH_FAILED'] = { | ||||||||||||||||||||||||||||
| 'severity': 'warning', | ||||||||||||||||||||||||||||
| 'summary': 'failed to probe daemons or devices', | ||||||||||||||||||||||||||||
| 'count': len(failures), | ||||||||||||||||||||||||||||
| 'detail': failures, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| health_changed = True | ||||||||||||||||||||||||||||
| elif 'CEPHADM_REFRESH_FAILED' in self.health_checks: | ||||||||||||||||||||||||||||
| del self.health_checks['CEPHADM_REFRESH_FAILED'] | ||||||||||||||||||||||||||||
| health_changed = True | ||||||||||||||||||||||||||||
| if health_changed: | ||||||||||||||||||||||||||||
| self.set_health_checks(self.health_checks) | ||||||||||||||||||||||||||||
| self.log.debug('refreshing hosts and daemons') | ||||||||||||||||||||||||||||
| self._refresh_hosts_and_daemons() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self._check_for_strays() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -549,6 +512,10 @@ def serve(self): | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self.rm_util._remove_osds_bg() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self.migration.migrate() | ||||||||||||||||||||||||||||
| if self.migration.is_migration_ongoing(): | ||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if self._apply_all_services(): | ||||||||||||||||||||||||||||
| continue # did something, refresh | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -1158,6 +1125,58 @@ def _refresh_host_osdspec_previews(self, host) -> bool: | |||||||||||||||||||||||||||
| self.log.debug(f'Refreshed OSDSpec previews for host <{host}>') | ||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def _refresh_hosts_and_daemons(self): | ||||||||||||||||||||||||||||
| bad_hosts = [] | ||||||||||||||||||||||||||||
| failures = [] | ||||||||||||||||||||||||||||
| for host in self.cache.get_hosts(): | ||||||||||||||||||||||||||||
| if self.cache.host_needs_check(host): | ||||||||||||||||||||||||||||
| r = self._check_host(host) | ||||||||||||||||||||||||||||
| if r is not None: | ||||||||||||||||||||||||||||
| bad_hosts.append(r) | ||||||||||||||||||||||||||||
| if self.cache.host_needs_daemon_refresh(host): | ||||||||||||||||||||||||||||
| self.log.debug('refreshing %s daemons' % host) | ||||||||||||||||||||||||||||
| r = self._refresh_host_daemons(host) | ||||||||||||||||||||||||||||
| if r: | ||||||||||||||||||||||||||||
| failures.append(r) | ||||||||||||||||||||||||||||
| if self.cache.host_needs_device_refresh(host): | ||||||||||||||||||||||||||||
| self.log.debug('refreshing %s devices' % host) | ||||||||||||||||||||||||||||
| r = self._refresh_host_devices(host) | ||||||||||||||||||||||||||||
| if r: | ||||||||||||||||||||||||||||
| failures.append(r) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if self.cache.host_needs_osdspec_preview_refresh(host): | ||||||||||||||||||||||||||||
| self.log.debug(f"refreshing OSDSpec previews for {host}") | ||||||||||||||||||||||||||||
| r = self._refresh_host_osdspec_previews(host) | ||||||||||||||||||||||||||||
| if r: | ||||||||||||||||||||||||||||
| failures.append(r) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| health_changed = False | ||||||||||||||||||||||||||||
| if 'CEPHADM_HOST_CHECK_FAILED' in self.health_checks: | ||||||||||||||||||||||||||||
| del self.health_checks['CEPHADM_HOST_CHECK_FAILED'] | ||||||||||||||||||||||||||||
| health_changed = True | ||||||||||||||||||||||||||||
| if bad_hosts: | ||||||||||||||||||||||||||||
| self.health_checks['CEPHADM_HOST_CHECK_FAILED'] = { | ||||||||||||||||||||||||||||
| 'severity': 'warning', | ||||||||||||||||||||||||||||
| 'summary': '%d hosts fail cephadm check' % len(bad_hosts), | ||||||||||||||||||||||||||||
| 'count': len(bad_hosts), | ||||||||||||||||||||||||||||
| 'detail': bad_hosts, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| health_changed = True | ||||||||||||||||||||||||||||
| if failures: | ||||||||||||||||||||||||||||
| self.health_checks['CEPHADM_REFRESH_FAILED'] = { | ||||||||||||||||||||||||||||
| 'severity': 'warning', | ||||||||||||||||||||||||||||
| 'summary': 'failed to probe daemons or devices', | ||||||||||||||||||||||||||||
| 'count': len(failures), | ||||||||||||||||||||||||||||
| 'detail': failures, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| health_changed = True | ||||||||||||||||||||||||||||
| elif 'CEPHADM_REFRESH_FAILED' in self.health_checks: | ||||||||||||||||||||||||||||
| del self.health_checks['CEPHADM_REFRESH_FAILED'] | ||||||||||||||||||||||||||||
| health_changed = True | ||||||||||||||||||||||||||||
| if health_changed: | ||||||||||||||||||||||||||||
| self.set_health_checks(self.health_checks) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def _refresh_host_daemons(self, host): | ||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||
| out, err, code = self._run_cephadm( | ||||||||||||||||||||||||||||
|
|
@@ -1995,6 +2014,8 @@ def add_mgr(self, spec): | |||||||||||||||||||||||||||
| return self._add_daemon('mgr', spec, self.mgr_service.create) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def _apply(self, spec: GenericSpec) -> str: | ||||||||||||||||||||||||||||
| self.migration.verify_no_migration() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if spec.service_type == 'host': | ||||||||||||||||||||||||||||
| return self._add_host(cast(HostSpec, spec)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/will then then randomly/will then randomly/