diff --git a/conanfile.py b/conanfile.py index 99b915a..37fc5af 100644 --- a/conanfile.py +++ b/conanfile.py @@ -9,7 +9,7 @@ class HomeBlocksConan(ConanFile): name = "homeblocks" - version = "0.0.15" + version = "1.0.15" homepage = "https://github.com/eBay/HomeBlocks" description = "Block Store built on HomeStore" topics = ("ebay") diff --git a/src/include/homeblks/home_blks.hpp b/src/include/homeblks/home_blks.hpp index db8bae7..4b9e159 100644 --- a/src/include/homeblks/home_blks.hpp +++ b/src/include/homeblks/home_blks.hpp @@ -59,7 +59,7 @@ class HomeBlocksApplication { virtual uint64_t app_mem_size() const = 0; // Callback made after determining if a SvcId exists or not during initialization, will consume response - virtual peer_id_t discover_svcid(std::optional< peer_id_t > const& found) const = 0; + virtual std::optional< peer_id_t > discover_svc_id(std::optional< peer_id_t > const& found) const = 0; }; struct HomeBlocksStats { diff --git a/src/lib/homeblks_impl.cpp b/src/lib/homeblks_impl.cpp index 71102a1..3afb744 100644 --- a/src/lib/homeblks_impl.cpp +++ b/src/lib/homeblks_impl.cpp @@ -14,7 +14,8 @@ * *********************************************************************************/ #include - +#include +#include #include #include #include @@ -119,8 +120,8 @@ class HBReplApp : public homestore::ReplApplication { homestore::replica_id_t get_my_repl_id() const override { return hb_->our_uuid(); } - void destroy_repl_dev_listener(homestore::group_id_t) override { - LOGERROR("destroy_repl_dev_listener Unimplimented"); + void destroy_repl_dev_listener(homestore::group_id_t gid) override { + LOGI("Destroying repl dev listener for group_id {}", boost::uuids::to_string(gid)); } private: @@ -182,7 +183,11 @@ void HomeBlocksImpl::init_homestore() { .start(hs_input_params{.devices = device_info, .app_mem_size = app_mem_size}, [this]() { register_metablk_cb(); }); if (need_format) { - LOGI("We are starting for the first time. Formatting HomeStore. "); + auto ret = app->discover_svc_id(std::nullopt); + DEBUG_ASSERT(ret.has_value(), "UUID should be generated by application."); + our_uuid_ = ret.value(); + LOGINFO("We are starting for the first time on svc_id: [{}]. Formatting HomeStore. ", + boost::uuids::to_string(our_uuid())); if (has_data_dev && has_fast_dev) { // NOTE: chunk_size, num_chunks only has to specify one, can be deduced from each other. homestore::hs()->format_and_start({ @@ -216,6 +221,12 @@ void HomeBlocksImpl::init_homestore() { } // repl_app->on_repl_devs_init_completed(); superblk_init(); + } else { + // we are starting on an existing system; + DEBUG_ASSERT(our_uuid() != boost::uuids::nil_uuid(), "UUID should be recovered from HB superblock!"); + // now callback to application to nofity the uuid so that we are treated as an existing system; + app->discover_svc_id(our_uuid()); + LOGINFO("We are starting on [{}].", boost::uuids::to_string(our_uuid_)); } recovery_done_ = true; @@ -228,6 +239,7 @@ void HomeBlocksImpl::superblk_init() { sb_->version = HB_SB_VER; sb_->boot_cnt = 0; sb_->init_flag(0); + sb_->svc_id = our_uuid_; sb_.write(); } @@ -247,6 +259,10 @@ void HomeBlocksImpl::on_hb_meta_blk_found(sisl::byte_view const& buf, void* cook ++sb_->boot_cnt; + our_uuid_ = sb_->svc_id; + + LOGI("HomeBlks superblock loaded, boot_cnt: {}, svc_id: {}", sb_->boot_cnt, boost::uuids::to_string(our_uuid_)); + // avoid doing sb meta blk write in callback which will cause deadlock; // the 1st CP should flush all dirty SB before taking traffic; } diff --git a/src/lib/homeblks_impl.hpp b/src/lib/homeblks_impl.hpp index ed6b833..b69a991 100644 --- a/src/lib/homeblks_impl.hpp +++ b/src/lib/homeblks_impl.hpp @@ -36,6 +36,7 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab uint32_t version; uint32_t flag; uint64_t boot_cnt; + peer_id_t svc_id; void init_flag(uint32_t f) { flag = f; } void set_flag(uint32_t bit) { flag |= bit; } @@ -67,6 +68,7 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab bool recovery_done_{false}; superblk< homeblks_sb_t > sb_; + peer_id_t our_uuid_; public: explicit HomeBlocksImpl(std::weak_ptr< HomeBlocksApplication >&& application); @@ -84,10 +86,7 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab HomeBlocksStats get_stats() const final; iomgr::drive_type data_drive_type() const final; - peer_id_t our_uuid() const final { - // not expected to be called; - return peer_id_t{}; - } + peer_id_t our_uuid() const final { return our_uuid_; } /// VolumeManager NullAsyncResult create_volume(VolumeInfo&& vol_info) final; diff --git a/src/lib/volume/tests/test_common.hpp b/src/lib/volume/tests/test_common.hpp index ff4cadc..e88fca6 100644 --- a/src/lib/volume/tests/test_common.hpp +++ b/src/lib/volume/tests/test_common.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -82,7 +83,9 @@ class HBTestHelper { return devs; } - peer_id_t discover_svcid(std::optional< peer_id_t > const&) const override { return helper_.svc_id(); } + std::optional< peer_id_t > discover_svc_id(std::optional< peer_id_t > const&) const override { + return helper_.svc_id(); + } uint64_t app_mem_size() const override { // return SISL_OPTIONS["app_mem_size"].as< uint64_t >(); @@ -99,7 +102,7 @@ class HBTestHelper { sisl::logging::SetLogPattern("[%D %T%z] [%^%L%$] [%n] [%t] %v"); // init svc_id_ - svc_id_ = boost::uuids::nil_uuid(); + svc_id_ = boost::uuids::random_generator()(); // init device list init_dev_list(true /*init_device*/);