From: Kefu Chai Date: Fri, 21 Jun 2019 11:00:56 +0000 (+0800) Subject: crimson/osd: add osd to crush when it boots X-Git-Tag: v15.1.0~2368^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F28689%2Fhead;p=ceph.git crimson/osd: add osd to crush when it boots 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 --- diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index a21cabaac104..487104a9a48c 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -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("osd_crush_update_on_start")) { + return seastar::now(); + } + const double weight = [this] { + if (auto w = local_conf().get_val("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().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(); diff --git a/src/crimson/osd/osd.h b/src/crimson/osd/osd.h index 25c7652cbb05..82969c449a61 100644 --- a/src/crimson/osd/osd.h +++ b/src/crimson/osd/osd.h @@ -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> make_pg(cached_map_t create_map, spg_t pgid); seastar::future> load_pg(spg_t pgid);