From eec84bb80c3074f64abe38e01f5ecb807625dc48 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 18 Jul 2021 22:44:59 +0800 Subject: [PATCH] crimson/osd: create store in main() to initialize an alienstore with a reference of seastar::alien::instance is but the internal of AlienStore, would be better if we could avoid exposing it as a part of the interface of crimson::osd::OSD(). so, in this change, instead of creating FuturizedStore in OSD(), we create it in main() where the app is available, so we can just create FuturizedStore without passing the alien instance all the way down to OSD(). Signed-off-by: Kefu Chai --- src/crimson/osd/main.cc | 8 +++++- src/crimson/osd/osd.cc | 60 +++++++++++++++++++---------------------- src/crimson/osd/osd.h | 8 ++---- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/crimson/osd/main.cc b/src/crimson/osd/main.cc index b5ff8570a067b..48519c600ea17 100644 --- a/src/crimson/osd/main.cc +++ b/src/crimson/osd/main.cc @@ -284,8 +284,14 @@ int main(int argc, char* argv[]) nonce); configure_crc_handling(*msgr); } + auto store = crimson::os::FuturizedStore::create( + local_conf().get_val("osd_objectstore"), + local_conf().get_val("osd_data"), + local_conf().get_config_values(), + app.alien()); + osd.start_single(whoami, nonce, - std::ref(app.alien()), + std::ref(*store), cluster_msgr, client_msgr, hb_front_msgr, hb_back_msgr).get(); auto stop_osd = seastar::defer([&] { diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index b96b3af083c67..17acd6f01a91e 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -70,7 +70,7 @@ using crimson::os::FuturizedStore; namespace crimson::osd { OSD::OSD(int id, uint32_t nonce, - seastar::alien::instance& alien, + crimson::os::FuturizedStore& store, crimson::net::MessengerRef cluster_msgr, crimson::net::MessengerRef public_msgr, crimson::net::MessengerRef hb_front_msgr, @@ -83,12 +83,8 @@ OSD::OSD(int id, uint32_t nonce, public_msgr{public_msgr}, monc{new crimson::mon::Client{*public_msgr, *this}}, mgrc{new crimson::mgr::Client{*public_msgr, *this}}, - store{crimson::os::FuturizedStore::create( - local_conf().get_val("osd_objectstore"), - local_conf().get_val("osd_data"), - local_conf().get_config_values(), - alien)}, - shard_services{*this, whoami, *cluster_msgr, *public_msgr, *monc, *mgrc, *store}, + store{store}, + shard_services{*this, whoami, *cluster_msgr, *public_msgr, *monc, *mgrc, store}, heartbeat{new Heartbeat{whoami, shard_services, *monc, hb_front_msgr, hb_back_msgr}}, // do this in background tick_timer{[this] { @@ -147,20 +143,20 @@ CompatSet get_osd_initial_compat_set() seastar::future<> OSD::mkfs(uuid_d osd_uuid, uuid_d cluster_fsid) { - return store->start().then([this, osd_uuid] { - return store->mkfs(osd_uuid); + return store.start().then([this, osd_uuid] { + return store.mkfs(osd_uuid); }).then([this] { - return store->mount(); + return store.mount(); }).then([cluster_fsid, this] { superblock.cluster_fsid = cluster_fsid; - superblock.osd_fsid = store->get_fsid(); + superblock.osd_fsid = store.get_fsid(); superblock.whoami = whoami; superblock.compat_features = get_osd_initial_compat_set(); return _write_superblock(); }).then([cluster_fsid, this] { return when_all_succeed( - store->write_meta("ceph_fsid", cluster_fsid.to_string()), - store->write_meta("whoami", std::to_string(whoami))); + store.write_meta("ceph_fsid", cluster_fsid.to_string()), + store.write_meta("whoami", std::to_string(whoami))); }).then_unpack([cluster_fsid, this] { fmt::print("created object store {} for osd.{} fsid {}\n", local_conf().get_val("osd_data"), @@ -171,10 +167,10 @@ seastar::future<> OSD::mkfs(uuid_d osd_uuid, uuid_d cluster_fsid) seastar::future<> OSD::_write_superblock() { - return store->open_collection(coll_t::meta()).then([this] (auto ch) { + return store.open_collection(coll_t::meta()).then([this] (auto ch) { if (ch) { // if we already have superblock, check if it matches - meta_coll = make_unique(ch, store.get()); + meta_coll = make_unique(ch, &store); return meta_coll->load_superblock().then([this](OSDSuperblock&& sb) { if (sb.cluster_fsid != superblock.cluster_fsid) { logger().error("provided cluster fsid {} != superblock's {}", @@ -194,12 +190,12 @@ seastar::future<> OSD::_write_superblock() __func__, superblock.cluster_fsid, superblock.osd_fsid); - return store->create_new_collection(coll_t::meta()).then([this] (auto ch) { - meta_coll = make_unique(ch , store.get()); + return store.create_new_collection(coll_t::meta()).then([this] (auto ch) { + meta_coll = make_unique(ch , &store); ceph::os::Transaction t; meta_coll->create(t); meta_coll->store_superblock(t, superblock); - return store->do_transaction(meta_coll->collection(), std::move(t)); + return store.do_transaction(meta_coll->collection(), std::move(t)); }); } }); @@ -252,12 +248,12 @@ seastar::future<> OSD::start() startup_time = ceph::mono_clock::now(); - return store->start().then([this] { - return store->mount(); + return store.start().then([this] { + return store.mount(); }).then([this] { - return store->open_collection(coll_t::meta()); + return store.open_collection(coll_t::meta()); }).then([this](auto ch) { - meta_coll = make_unique(ch, store.get()); + meta_coll = make_unique(ch, &store); return meta_coll->load_superblock(); }).then([this](OSDSuperblock&& sb) { superblock = std::move(sb); @@ -414,7 +410,7 @@ seastar::future<> OSD::_add_me_to_crush() w >= 0) { return seastar::make_ready_future(w); } else { - return store->stat().then([](auto st) { + return store.stat().then([](auto st) { auto total = st.total; return seastar::make_ready_future( std::max(.00001, @@ -490,9 +486,9 @@ seastar::future<> OSD::stop() return asok->stop().then([this] { return heartbeat->stop(); }).then([this] { - return store->umount(); + return store.umount(); }).then([this] { - return store->stop(); + return store.stop(); }).then([this] { return seastar::parallel_for_each(pg_map.get_pgs(), [](auto& p) { @@ -549,7 +545,7 @@ void OSD::print(std::ostream& out) const seastar::future<> OSD::load_pgs() { - return store->list_collections().then([this](auto colls) { + return store.list_collections().then([this](auto colls) { return seastar::parallel_for_each(colls, [this](auto coll) { spg_t pgid; if (coll.is_pg(&pgid)) { @@ -595,9 +591,9 @@ seastar::future> OSD::make_pg(cached_map_t create_map, auto get_collection = [pgid, do_create, this] { const coll_t cid{pgid}; if (do_create) { - return store->create_new_collection(cid); + return store.create_new_collection(cid); } else { - return store->open_collection(cid); + return store.open_collection(cid); } }; return seastar::when_all( @@ -622,14 +618,14 @@ seastar::future> OSD::load_pg(spg_t pgid) { logger().debug("{}: {}", __func__, pgid); - return seastar::do_with(PGMeta(store.get(), pgid), [] (auto& pg_meta) { + return seastar::do_with(PGMeta(&store, pgid), [] (auto& pg_meta) { return pg_meta.get_epoch(); }).then([this](epoch_t e) { return get_map(e); }).then([pgid, this] (auto&& create_map) { return make_pg(std::move(create_map), pgid, false); }).then([this](Ref pg) { - return pg->read_state(store.get()).then([pg] { + return pg->read_state(&store).then([pg] { return seastar::make_ready_future>(std::move(pg)); }); }).handle_exception([pgid](auto ep) { @@ -752,7 +748,7 @@ void OSD::update_stats() osd_stat.hb_peers = heartbeat->get_peers(); osd_stat.seq = (static_cast(get_up_epoch()) << 32) | osd_stat_seq; gate.dispatch_in_background("statfs", *this, [this] { - (void) store->stat().then([this](store_statfs_t&& st) { + (void) store.stat().then([this](store_statfs_t&& st) { osd_stat.statfs = st; }); }); @@ -1034,7 +1030,7 @@ seastar::future<> OSD::handle_osd_map(crimson::net::ConnectionRef conn, superblock.clean_thru = last; } meta_coll->store_superblock(t, superblock); - return store->do_transaction(meta_coll->collection(), std::move(t)); + return store.do_transaction(meta_coll->collection(), std::move(t)); }); }).then([=] { // TODO: write to superblock and commit the transaction diff --git a/src/crimson/osd/osd.h b/src/crimson/osd/osd.h index 6d29282d0756a..731ebeb59b638 100644 --- a/src/crimson/osd/osd.h +++ b/src/crimson/osd/osd.h @@ -40,10 +40,6 @@ class OSDMap; class OSDMeta; class Heartbeat; -namespace seastar::alien { - class instance; -} - namespace ceph::os { class Transaction; } @@ -81,7 +77,7 @@ class OSD final : public crimson::net::Dispatcher, SimpleLRU map_bl_cache; cached_map_t osdmap; // TODO: use a wrapper for ObjectStore - std::unique_ptr store; + crimson::os::FuturizedStore& store; std::unique_ptr meta_coll; OSDState state; @@ -125,7 +121,7 @@ class OSD final : public crimson::net::Dispatcher, public: OSD(int id, uint32_t nonce, - seastar::alien::instance& alien, + crimson::os::FuturizedStore& store, crimson::net::MessengerRef cluster_msgr, crimson::net::MessengerRef client_msgr, crimson::net::MessengerRef hb_front_msgr, -- 2.39.5