]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: support creation of daemons with ranks
authorSage Weil <sage@newdream.net>
Fri, 23 Apr 2021 19:31:14 +0000 (15:31 -0400)
committerSage Weil <sage@newdream.net>
Thu, 3 Jun 2021 12:37:12 +0000 (07:37 -0500)
- we need to assign all names and update the rank_map before we start
creating daemons.
- if we are using ranks, we should delete old daemons first, and
fence them from the cluster (where possible).

Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit e8b07982b50e35a546a52b092cac5a825c37981d)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/serve.py
src/pybind/mgr/cephadm/services/cephadmservice.py

index 7bc89c46c2bd4a2e30dbb02d6f6903cf23f39406..15e0ae604987b5de57b690439cf38b8a95d05b3b 100644 (file)
@@ -2246,12 +2246,14 @@ Then run the following:
                     'service_type': spec.service_type,
                     'data': self._preview_osdspecs(osdspecs=[cast(DriveGroupSpec, spec)])}
 
+        svc = self.cephadm_services[spec.service_type]
         ha = HostAssignment(
             spec=spec,
             hosts=self._schedulable_hosts(),
             networks=self.cache.networks,
             daemons=self.cache.get_daemons_by_service(spec.service_name()),
-            allow_colo=self.cephadm_services[spec.service_type].allow_colo(),
+            allow_colo=svc.allow_colo(),
+            rank_map=self.spec_store[spec.service_name()].rank_map if svc.ranked() else None
         )
         ha.validate()
         hosts, to_add, to_remove = ha.place()
index 08cc4445d1bbe2a55edb70a8cc02a7b8c6bd29ce..f4499cba07d29588ed5e9df07f8a286d9b94552d 100644 (file)
@@ -664,6 +664,9 @@ class CephadmServe:
             )
             return False
 
+        rank_map = None
+        if svc.ranked():
+            rank_map = self.mgr.spec_store[spec.service_name()].rank_map or {}
         ha = HostAssignment(
             spec=spec,
             hosts=self.mgr._schedulable_hosts(),
@@ -676,6 +679,7 @@ class CephadmServe:
             allow_colo=svc.allow_colo(),
             primary_daemon_type=svc.primary_daemon_type(),
             per_host_daemon_type=svc.per_host_daemon_type(),
+            rank_map=rank_map,
         )
 
         try:
@@ -703,6 +707,40 @@ class CephadmServe:
         self.log.debug('Hosts that will receive new daemons: %s' % slots_to_add)
         self.log.debug('Daemons that will be removed: %s' % daemons_to_remove)
 
+        # assign names
+        for i in range(len(slots_to_add)):
+            slot = slots_to_add[i]
+            slot = slot.assign_name(self.mgr.get_unique_name(
+                slot.daemon_type,
+                slot.hostname,
+                daemons,
+                prefix=spec.service_id,
+                forcename=slot.name,
+                rank=slot.rank,
+                rank_generation=slot.rank_generation,
+            ))
+            slots_to_add[i] = slot
+            if rank_map is not None:
+                assert slot.rank is not None
+                assert slot.rank_generation is not None
+                assert rank_map[slot.rank][slot.rank_generation] is None
+                rank_map[slot.rank][slot.rank_generation] = slot.name
+
+        if rank_map:
+            # record the rank_map before we make changes so that if we fail the
+            # next mgr will clean up.
+            self.mgr.spec_store.save_rank_map(spec.service_name(), rank_map)
+
+            # remove daemons now, since we are going to fence them anyway
+            for d in daemons_to_remove:
+                assert d.hostname is not None
+                self._remove_daemon(d.name(), d.hostname)
+            daemons_to_remove = []
+
+            # fence them
+            svc.fence_old_ranks(spec, rank_map, len(all_slots))
+
+        # create daemons
         for slot in slots_to_add:
             # first remove daemon on conflicting port?
             if slot.ports:
@@ -723,13 +761,7 @@ class CephadmServe:
                     break
 
             # deploy new daemon
-            daemon_id = self.mgr.get_unique_name(
-                slot.daemon_type,
-                slot.hostname,
-                daemons,
-                prefix=spec.service_id,
-                forcename=slot.name)
-
+            daemon_id = slot.name
             if not did_config:
                 svc.config(spec, daemon_id)
                 did_config = True
index 66c6a92b7270efc124106d3dcd4a3c60140bc94b..96e459c70a7e713029ae2a897b74871795ec0feb 100644 (file)
@@ -145,6 +145,19 @@ class CephadmService(metaclass=ABCMeta):
         """
         return None
 
+    def ranked(self) -> bool:
+        """
+        If True, we will assign a stable rank (0, 1, ...) and monotonically increasing
+        generation (0, 1, ...) to each daemon we create/deploy.
+        """
+        return False
+
+    def fence_old_ranks(self,
+                        spec: ServiceSpec,
+                        rank_map: Dict[int, Dict[int, Optional[str]]],
+                        num_ranks: int) -> None:
+        assert False
+
     def make_daemon_spec(
             self,
             host: str,