]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: create store in main()
authorKefu Chai <kchai@redhat.com>
Sun, 18 Jul 2021 14:44:59 +0000 (22:44 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 19 Jul 2021 01:13:21 +0000 (09:13 +0800)
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 <kchai@redhat.com>
src/crimson/osd/main.cc
src/crimson/osd/osd.cc
src/crimson/osd/osd.h

index b5ff8570a067b390cb721eb3a0eb0a4fa102e6ff..48519c600ea17c2faf20857eb38b1698a0d8163e 100644 (file)
@@ -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<std::string>("osd_objectstore"),
+            local_conf().get_val<std::string>("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([&] {
index b96b3af083c671e74ebcb850b8efe0638f93285b..17acd6f01a91eafbf81b84f224cca28d9f319ec2 100644 (file)
@@ -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<std::string>("osd_objectstore"),
-      local_conf().get_val<std::string>("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<std::string>("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<OSDMeta>(ch, store.get());
+      meta_coll = make_unique<OSDMeta>(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<OSDMeta>(ch , store.get());
+      return store.create_new_collection(coll_t::meta()).then([this] (auto ch) {
+        meta_coll = make_unique<OSDMeta>(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<OSDMeta>(ch, store.get());
+    meta_coll = make_unique<OSDMeta>(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<double>(w);
     } else {
-       return store->stat().then([](auto st) {
+       return store.stat().then([](auto st) {
          auto total = st.total;
         return seastar::make_ready_future<double>(
            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<Ref<PG>> 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<Ref<PG>> 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> pg) {
-    return pg->read_state(store.get()).then([pg] {
+    return pg->read_state(&store).then([pg] {
        return seastar::make_ready_future<Ref<PG>>(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<uint64_t>(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
index 6d29282d0756a92e208295e49eaf842ec104aa37..731ebeb59b638b0accbbd8cd95f86598035c797b 100644 (file)
@@ -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<epoch_t, bufferlist, false> map_bl_cache;
   cached_map_t osdmap;
   // TODO: use a wrapper for ObjectStore
-  std::unique_ptr<crimson::os::FuturizedStore> store;
+  crimson::os::FuturizedStore& store;
   std::unique_ptr<OSDMeta> 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,