]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: add osd to crush when it boots 28689/head
authorKefu Chai <kchai@redhat.com>
Fri, 21 Jun 2019 11:00:56 +0000 (19:00 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 21 Jun 2019 12:31:47 +0000 (20:31 +0800)
this maps the corresponding behavior of classic OSD, we could rely on
the start script to do this job. but statfs reported by object storage
is more accurate than what we have using `df`.

in future, we could extract this feature out of crimson-osd by querying
crimson-osd for the size of underlying storage. and prepare the mon
command using a script. but let's have this function builtin in
crimson-osd at this moment. so it's compatible with classic OSD.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/osd.cc
src/crimson/osd/osd.h

index a21cabaac1047fd8e182c970893756eed5d42a10..487104a9a48ca46e030e598e06526e7357baf988 100644 (file)
@@ -209,6 +209,8 @@ seastar::future<> OSD::start()
   }).then([this] {
     return seastar::when_all_succeed(monc->start(),
                                      mgrc->start());
+  }).then([this] {
+    return _add_me_to_crush();
   }).then([this] {
     monc->sub_want("osd_pg_creates", last_pg_create_epoch, 0);
     monc->sub_want("mgrmap", 0, 0);
@@ -285,6 +287,40 @@ seastar::future<> OSD::_send_boot()
   return monc->send_message(m);
 }
 
+seastar::future<> OSD::_add_me_to_crush()
+{
+  if (!local_conf().get_val<bool>("osd_crush_update_on_start")) {
+    return seastar::now();
+  }
+  const double weight = [this] {
+    if (auto w = local_conf().get_val<double>("osd_crush_initial_weight");
+       w >= 0) {
+      return w;
+    } else {
+      auto total = store->stat().total;
+      return std::max(.00001, double(total) / double(1ull << 40)); // TB
+    }
+  }();
+  const CrushLocation loc{make_unique<CephContext>().get()};
+  logger().info("{} crush location is {}", __func__, loc);
+  string cmd = fmt::format(R"({{
+    "prefix": "osd crush create-or-move",
+    "id": {},
+    "weight": {:.4f},
+    "args": [{}]
+  }})", whoami, weight, loc);
+  return monc->run_command({cmd}, {}).then(
+    [this](int32_t code, string message, bufferlist) {
+      if (code) {
+       logger().warn("fail to add to crush: {} ({})", message, code);
+       throw std::runtime_error("fail to add to crush");
+      } else {
+       logger().info("added to crush: {}", message);
+      }
+      return seastar::now();
+    });
+}
+
 seastar::future<> OSD::_send_alive()
 {
   auto want = osdmap->get_epoch();
index 25c7652cbb054b5510681d4ef19ac96724f65ef5..82969c449a614afc2d422fe4e37a5d758ffa507e 100644 (file)
@@ -124,6 +124,7 @@ private:
   seastar::future<> start_boot();
   seastar::future<> _preboot(version_t oldest_osdmap, version_t newest_osdmap);
   seastar::future<> _send_boot();
+  seastar::future<> _add_me_to_crush();
 
   seastar::future<Ref<PG>> make_pg(cached_map_t create_map, spg_t pgid);
   seastar::future<Ref<PG>> load_pg(spg_t pgid);