Skip to content

Commit

Permalink
add HB and vol meta svc register and recovery cb
Browse files Browse the repository at this point in the history
  • Loading branch information
yamingk committed Feb 22, 2025
1 parent ae7e64f commit 09391cf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
57 changes: 47 additions & 10 deletions src/lib/homeblks_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,29 +187,66 @@ void HomeBlocksImpl::init_homestore() {
}

void HomeBlocksImpl::superblk_init() {
auto sb = homestore::superblk< homeblks_sb_t >(HB_META_NAME);
sb.create(sizeof(homeblks_sb_t));
sb->magic = HB_SB_MAGIC;
sb->version = HB_SB_VER;
sb->boot_cnt = 0;
sb->init_flag(0);
sb.write();
sb_ = homestore::superblk< homeblks_sb_t >(HB_META_NAME);
sb_.create(sizeof(homeblks_sb_t));
sb_->magic = HB_SB_MAGIC;
sb_->version = HB_SB_VER;
sb_->boot_cnt = 0;
sb_->init_flag(0);
sb_.write();
}

void HomeBlocksImpl::on_vol_meta_blk_found(sisl::byte_view const& buf, void* cookie) {
// auto sb = homestore::superblk< vol_sb_t >(VOL_META_NAME);
// sb.load(buf, cookie);
// TODO:
}

void HomeBlocksImpl::on_hb_meta_blk_found(sisl::byte_view const& buf, void* cookie) {
sb_ = homestore::superblk< homeblks_sb_t >(HB_META_NAME);
sb_.load(buf, cookie);
// sb verification
RELEASE_ASSERT_EQ(sb_->version, HB_SB_VER);
RELEASE_ASSERT_EQ(sb_->magic, HB_SB_MAGIC);

if (sb_->test_flag(SB_FLAGS_GRACEFUL_SHUTDOWN)) {
// if it is a gracefuln shutdown, this flag should be set again in shutdown routine;
sb_->clear_flag(SB_FLAGS_GRACEFUL_SHUTDOWN);
LOGI("System was shutdown gracefully");
} else {
LOGI("System experienced sudden crash since last boot");
}

++sb_->boot_cnt;

// avoid doing sb meta blk write in callback which will cause deadlock;
// the 1st CP should flush all dirty SB before taking traffic;
}

void HomeBlocksImpl::register_metablk_cb() {
// register some callbacks for metadata recovery;
using namespace homestore;

// HomeBlks SB
HomeStore::instance()->meta_service().register_handler(
HB_META_NAME,
[this](homestore::meta_blk* mblk, sisl::byte_view buf, size_t size) {
auto sb = homestore::superblk< homeblks_sb_t >(HB_META_NAME);
sb.load(buf, mblk);
on_hb_meta_blk_found(std::move(buf), voidptr_cast(mblk));
},
nullptr /*recovery_comp_cb*/, true /* do_crc */);

// Volume SB
HomeStore::instance()->meta_service().register_handler(
VOL_META_NAME,
[this](homestore::meta_blk* mblk, sisl::byte_view buf, size_t size) {
on_vol_meta_blk_found(std::move(buf), voidptr_cast(mblk));
},
nullptr /*recovery_comp_cb*/, true /* do_crc */);
}

void HomeBlocksImpl::on_init_complete() {
// TODO: register to meta service for HomeBlks meta block handler;
// this is called after HomeStore all recovery completed.
// Add anything that needs to be done here.
}

void HomeBlocksImpl::init_cp() {}
Expand Down
9 changes: 8 additions & 1 deletion src/lib/homeblks_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab

private:
inline static auto const HB_META_NAME = std::string("HomeBlks2");
inline static auto const VOL_META_NAME = std::string("Volume2");
static constexpr uint64_t HB_SB_MAGIC{0xCEEDDEEB};
static constexpr uint32_t HB_SB_VER{0x1};
static constexpr uint64_t HS_CHUNK_SIZE = 2 * Gi;
static constexpr uint32_t DATA_BLK_SIZE = 4096;
static constexpr uint32_t SB_FLAGS_CLEAN_SHUTDOWN{0x00000001};
static constexpr uint32_t SB_FLAGS_GRACEFUL_SHUTDOWN{0x00000001};
static constexpr uint32_t SB_FLAGS_RESTRICTED{0x00000002};

private:
Expand All @@ -80,6 +81,7 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab
std::map< volume_id_t, unique< Volume > > _volume_map;

bool recovery_done_{false};
homestore::superblk< homeblks_sb_t > sb_;

public:
explicit HomeBlocksImpl(std::weak_ptr< HomeBlocksApplication >&& application);
Expand Down Expand Up @@ -129,8 +131,13 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab

void get_dev_info(shared< HomeBlocksApplication > app, std::vector< homestore::dev_info >& device_info,
bool& has_data_dev, bool& has_fast_dev);

DevType get_device_type(std::string const& devname);
auto defer() const { return folly::makeSemiFuture().via(executor_); }

// recovery apis
void on_hb_meta_blk_found(sisl::byte_view const& buf, void* cookie);
void on_vol_meta_blk_found(sisl::byte_view const& buf, void* cookie);
};

class HBIndexSvcCB : public homestore::IndexServiceCallbacks {
Expand Down

0 comments on commit 09391cf

Please sign in to comment.