]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/osd: convert PGAdvanceMap::start to use coroutines
authorAishwarya Mathuria <amathuri@redhat.com>
Thu, 18 Dec 2025 06:01:26 +0000 (11:31 +0530)
committerAishwarya Mathuria <amathuri@redhat.com>
Fri, 16 Jan 2026 12:09:09 +0000 (17:39 +0530)
Rewrite PGAdvanceMap::start() using C++20 coroutines

Signed-off-by: Aishwarya Mathuria <amathuri@redhat.com>
src/crimson/osd/osd_operations/pg_advance_map.cc

index e136e168ca821bc698cd335167ef82bfc5cf5858..79426060ae3c2be7c8578160032d2848f055e6e7 100644 (file)
@@ -66,55 +66,52 @@ seastar::future<> PGAdvanceMap::start()
   using cached_map_t = OSDMapService::cached_map_t;
 
   DEBUG("{}: start", *this);
-
   IRef ref = this;
-  return enter_stage<>(
-    peering_pp(*pg).process
-  ).then([this, FNAME] {
-    /*
-     * PGAdvanceMap is scheduled at pg creation and when
-     * broadcasting new osdmaps to pgs. We are not able to serialize
-     * between the two different PGAdvanceMap callers since a new pg
-     * will get advanced to the latest osdmap at it's creation.
-     * As a result, we may need to adjust the PGAdvance operation
-     * 'from' epoch.
-     * See: https://tracker.ceph.com/issues/61744
-     */
-    from = pg->get_osdmap_epoch();
-    if (do_init) {
-      pg->handle_initialize(rctx);
-      pg->handle_activate_map(rctx);
-    }
-    ceph_assert(std::cmp_less_equal(*from, to));
-    return seastar::do_for_each(
-      boost::make_counting_iterator(*from + 1),
-      boost::make_counting_iterator(to + 1),
-      [this, FNAME](epoch_t next_epoch) {
-       DEBUG("{}: start: getting map {}",
-                      *this, next_epoch);
-       return shard_services.get_map(next_epoch).then(
-         [this, FNAME] (cached_map_t&& next_map) {
-           DEBUG("{}: advancing map to {}",
-                 *this, next_map->get_epoch());
-           pg->handle_advance_map(next_map, rctx);
-           return check_for_splits(*from, next_map);
-         });
-      }).then([this, FNAME] {
-       pg->handle_activate_map(rctx);
-       DEBUG("{}: map activated", *this);
-       if (do_init) {
-         shard_services.pg_created(pg->get_pgid(), pg);
-         INFO("PGAdvanceMap::start new pg {}", *pg);
-       }
-       return pg->complete_rctx(std::move(rctx));
-      });
-  }).then([this, FNAME] {
-    DEBUG("{}: complete", *this);
-    return handle.complete();
-  }).finally([this, FNAME, ref=std::move(ref)] {
+
+  // This executes when the function returns
+  auto finally = seastar::defer([this, FNAME] {
     DEBUG("{}: exit", *this);
     handle.exit();
   });
+
+  co_await enter_stage<>(peering_pp(*pg).process);
+  /*
+   * PGAdvanceMap is scheduled at pg creation and when
+   * broadcasting new osdmaps to pgs. We are not able to serialize
+   * between the two different PGAdvanceMap callers since a new pg
+   * will get advanced to the latest osdmap at it's creation.
+   * As a result, we may need to adjust the PGAdvance operation
+   * 'from' epoch.
+   * See: https://tracker.ceph.com/issues/61744
+   */
+  from = pg->get_osdmap_epoch();
+  if (do_init) {
+    pg->handle_initialize(rctx);
+    pg->handle_activate_map(rctx);
+  }
+  ceph_assert(std::cmp_less_equal(*from, to));
+
+  for (epoch_t next_epoch = *from + 1; next_epoch <= to; ++next_epoch) {
+    DEBUG("{}: start: getting map {}", *this, next_epoch);
+    cached_map_t next_map = co_await shard_services.get_map(next_epoch);
+    DEBUG("{}: advancing map to {}", *this, next_map->get_epoch());
+    
+    pg->handle_advance_map(next_map, rctx);
+    co_await check_for_splits(*from, next_map);
+  }
+
+  pg->handle_activate_map(rctx);
+  DEBUG("{}: map activated", *this);
+
+  if (do_init) {
+      shard_services.pg_created(pg->get_pgid(), pg);
+      INFO("PGAdvanceMap::start new pg {}", *pg);
+  }
+  co_await pg->complete_rctx(std::move(rctx));
+
+  DEBUG("{}: complete", *this);
+  co_await handle.complete();
+  co_return;
 }
 
 seastar::future<> PGAdvanceMap::check_for_splits(