Skip to content

Commit 12d0498

Browse files
authored
issue: 60 solo repl dev recovery (#65)
1 parent 4d9df23 commit 12d0498

File tree

7 files changed

+52
-40
lines changed

7 files changed

+52
-40
lines changed

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class HomeBlocksConan(ConanFile):
1111
name = "homeblocks"
12-
version = "0.0.5"
12+
version = "0.0.6"
1313

1414
homepage = "https://github.com/eBay/HomeBlocks"
1515
description = "Block Store built on HomeStore"

src/lib/homeblks_impl.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ HomeBlocksStats HomeBlocksImpl::get_stats() const {
4444
}
4545

4646
HomeBlocksImpl::~HomeBlocksImpl() {
47-
homestore::HomeStore::instance()->shutdown();
47+
homestore::hs()->shutdown();
4848
homestore::HomeStore::reset_instance();
4949
iomanager.stop();
5050
}
@@ -161,7 +161,7 @@ void HomeBlocksImpl::init_homestore() {
161161
// Note: timeline_consistency doesn't matter as we are using solo repl dev;
162162
auto repl_app =
163163
std::make_shared< HBReplApp >(repl_impl_type::solo, false /*timeline_consistency*/, this, _application);
164-
bool need_format = HomeStore::instance()
164+
bool need_format = homestore::hs()
165165
->with_index_service(std::make_unique< HBIndexSvcCB >(this))
166166
.with_repl_data_service(repl_app) // chunk selector defaulted to round_robine
167167
.start(hs_input_params{.devices = device_info, .app_mem_size = app_mem_size},
@@ -170,7 +170,7 @@ void HomeBlocksImpl::init_homestore() {
170170
LOGI("We are starting for the first time. Formatting HomeStore. ");
171171
if (has_data_dev && has_fast_dev) {
172172
// NOTE: chunk_size, num_chunks only has to specify one, can be deduced from each other.
173-
HomeStore::instance()->format_and_start({
173+
homestore::hs()->format_and_start({
174174
{HS_SERVICE::META, hs_format_params{.dev_type = HSDevType::Fast, .size_pct = 9.0}},
175175
{HS_SERVICE::LOG,
176176
hs_format_params{
@@ -186,7 +186,7 @@ void HomeBlocksImpl::init_homestore() {
186186
} else {
187187
auto run_on_type = has_fast_dev ? homestore::HSDevType::Fast : homestore::HSDevType::Data;
188188
LOGD("Running with Single mode, all service on {}", run_on_type);
189-
HomeStore::instance()->format_and_start({
189+
homestore::hs()->format_and_start({
190190
{HS_SERVICE::META, hs_format_params{.dev_type = run_on_type, .size_pct = 5.0}},
191191
{HS_SERVICE::LOG,
192192
hs_format_params{.dev_type = run_on_type, .size_pct = 10.0, .num_chunks = 0, .chunk_size = 32 * Mi}},
@@ -199,7 +199,7 @@ void HomeBlocksImpl::init_homestore() {
199199
.block_size = DATA_BLK_SIZE}},
200200
});
201201
}
202-
repl_app->on_repl_devs_init_completed();
202+
// repl_app->on_repl_devs_init_completed();
203203
superblk_init();
204204
}
205205

@@ -241,25 +241,29 @@ void HomeBlocksImpl::register_metablk_cb() {
241241
using namespace homestore;
242242

243243
// HomeBlks SB
244-
HomeStore::instance()->meta_service().register_handler(
244+
homestore::hs()->meta_service().register_handler(
245245
HB_META_NAME,
246246
[this](homestore::meta_blk* mblk, sisl::byte_view buf, size_t size) {
247247
on_hb_meta_blk_found(std::move(buf), voidptr_cast(mblk));
248248
},
249249
nullptr /*recovery_comp_cb*/, true /* do_crc */);
250+
}
251+
252+
void HomeBlocksImpl::on_init_complete() {
253+
// this is called after HomeStore all recovery completed.
254+
// Add anything that needs to be done here.
255+
using namespace homestore;
250256

251257
// Volume SB
252-
HomeStore::instance()->meta_service().register_handler(
258+
homestore::hs()->meta_service().register_handler(
253259
Volume::VOL_META_NAME,
254260
[this](homestore::meta_blk* mblk, sisl::byte_view buf, size_t size) {
255261
on_vol_meta_blk_found(std::move(buf), voidptr_cast(mblk));
256262
},
257-
nullptr /*recovery_comp_cb*/, true /* do_crc */);
258-
}
263+
nullptr /*recovery_comp_cb*/, true /* do_crc */,
264+
std::optional< meta_subtype_vec_t >({homestore::hs()->repl_service().get_meta_blk_name()}));
259265

260-
void HomeBlocksImpl::on_init_complete() {
261-
// this is called after HomeStore all recovery completed.
262-
// Add anything that needs to be done here.
266+
homestore::hs()->meta_service().read_sub_sb(Volume::VOL_META_NAME);
263267
}
264268

265269
void HomeBlocksImpl::init_cp() {}

src/lib/homeblks_impl.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab
6161
mutable std::shared_mutex vol_lock_;
6262
std::map< volume_id_t, VolumePtr > vol_map_;
6363

64+
mutable std::shared_mutex index_lock_;
65+
std::unordered_map< std::string, shared< VolumeIndexTable > > idx_tbl_map_;
66+
6467
bool recovery_done_{false};
6568
superblk< homeblks_sb_t > sb_;
6669

src/lib/volume/tests/test_volume.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ TEST_F(VolumeTest, CreateVolumeThenRecover) {
6868
ASSERT_TRUE(vinfo_ptr != nullptr);
6969
}
7070
}
71-
#if 0
71+
7272
g_helper->restart(5);
7373

7474
// verify the volumes are still there
@@ -82,7 +82,6 @@ TEST_F(VolumeTest, CreateVolumeThenRecover) {
8282
ASSERT_TRUE(vinfo_ptr != nullptr);
8383
}
8484
}
85-
#endif
8685
}
8786

8887
int main(int argc, char* argv[]) {

src/lib/volume/volume.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
namespace homeblocks {
2020

2121
// this API will be called by volume manager after volume sb is recovered and volume is created;
22-
shared< VolumeIndexTable > Volume::init_index_table(bool is_recovery,
23-
homestore::superblk< homestore::index_table_sb >&& sb) {
24-
index_cfg_t cfg(homestore::hs()->index_service().node_size());
25-
cfg.m_leaf_node_type = homestore::btree_node_type::PREFIX;
26-
cfg.m_int_node_type = homestore::btree_node_type::PREFIX;
27-
22+
shared< VolumeIndexTable > Volume::init_index_table(bool is_recovery, shared< VolumeIndexTable > tbl) {
2823
if (!is_recovery) {
24+
index_cfg_t cfg(homestore::hs()->index_service().node_size());
25+
cfg.m_leaf_node_type = homestore::btree_node_type::PREFIX;
26+
cfg.m_int_node_type = homestore::btree_node_type::PREFIX;
27+
2928
// create index table;
3029
auto uuid = hb_utils::gen_random_uuid();
3130

@@ -34,15 +33,11 @@ shared< VolumeIndexTable > Volume::init_index_table(bool is_recovery,
3433
LOGI("Creating index table for volume: {}, index_uuid: {}, parent_uuid: {}", vol_info_->name,
3534
boost::uuids::to_string(uuid), boost::uuids::to_string(id()));
3635
indx_tbl_ = std::make_shared< VolumeIndexTable >(uuid, id() /*parent uuid*/, 0 /*user_sb_size*/, cfg);
37-
homestore::hs()->index_service().add_index_table(indx_table());
3836
} else {
39-
// recovery path
40-
LOGI("Recovering index table for index_uuid: {}, parent_uuid: {}", boost::uuids::to_string(sb->uuid),
41-
boost::uuids::to_string(sb->parent_uuid));
42-
indx_tbl_ = std::make_shared< VolumeIndexTable >(std::move(sb), cfg);
43-
// HomeStore will add the index table to the index service in recovery case, its done in its constructor;
37+
indx_tbl_ = tbl;
4438
}
4539

40+
homestore::hs()->index_service().add_index_table(indx_table());
4641
return indx_table();
4742
}
4843

@@ -60,6 +55,9 @@ bool Volume::init(bool is_recovery) {
6055
sb_->init(vol_info_->page_size, vol_info_->size_bytes, vol_info_->id, vol_info_->name);
6156
// write to disk;
6257
sb_.write();
58+
59+
init_index_table(false /*is_recovery*/);
60+
6361
// create solo repl dev for volume;
6462
// members left empty on purpose for solo repl dev
6563
LOGI("Creating solo repl dev for volume: {}, uuid: {}", vol_info_->name, boost::uuids::to_string(id()));

src/lib/volume/volume.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ using VolumePtr = shared< Volume >;
3030
using VolIdxTablePtr = shared< VolumeIndexTable >;
3131

3232
using ReplDevPtr = shared< homestore::ReplDev >;
33+
using index_cfg_t = homestore::BtreeConfig;
3334
class Volume {
34-
using index_cfg_t = homestore::BtreeConfig;
3535

3636
public:
3737
inline static auto const VOL_META_NAME = std::string("Volume2"); // different from old releae;
@@ -90,16 +90,15 @@ class Volume {
9090

9191
VolIdxTablePtr indx_table() const { return indx_tbl_; }
9292
volume_id_t id() const { return vol_info_->id; };
93+
std::string id_str() const { return boost::uuids::to_string(vol_info_->id); };
9394
ReplDevPtr rd() const { return rd_; }
9495

9596
VolumeInfoPtr info() const { return vol_info_; }
9697

9798
//
98-
// This API is called for both volume creation and volume recovery;
9999
// Initialize index table for this volume and saves the index handle in the volume object;
100100
//
101-
shared< VolumeIndexTable > init_index_table(bool is_recovery,
102-
homestore::superblk< homestore::index_table_sb >&& sb = {});
101+
shared< VolumeIndexTable > init_index_table(bool is_recovery, shared< VolumeIndexTable > tbl = nullptr);
103102

104103
private:
105104
//

src/lib/volume_mgr.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ namespace homeblocks {
2222
std::shared_ptr< VolumeManager > HomeBlocksImpl::volume_manager() { return shared_from_this(); }
2323

2424
void HomeBlocksImpl::on_vol_meta_blk_found(sisl::byte_view const& buf, void* cookie) {
25-
// auto sb = homestore::superblk< vol_sb_t >(VOL_META_NAME);
26-
// sb.load(buf, cookie);
2725
auto vol_ptr = Volume::make_volume(buf, cookie);
28-
vol_ptr->init_index_table(false);
2926
auto id = vol_ptr->id();
27+
28+
{
29+
auto lg = std::scoped_lock(index_lock_);
30+
auto it = idx_tbl_map_.find(vol_ptr->id_str());
31+
DEBUG_ASSERT(it != idx_tbl_map_.end(), "index pid: {} not exists in recovery path, not expected!",
32+
boost::uuids::to_string(vol_ptr->id()));
33+
vol_ptr->init_index_table(true /*is_recovery*/, it->second /* table */);
34+
}
35+
3036
{
3137
auto lg = std::scoped_lock(vol_lock_);
3238
DEBUG_ASSERT(vol_map_.find(id) == vol_map_.end(),
@@ -36,14 +42,17 @@ void HomeBlocksImpl::on_vol_meta_blk_found(sisl::byte_view const& buf, void* coo
3642
}
3743

3844
shared< VolumeIndexTable > HomeBlocksImpl::recover_index_table(homestore::superblk< homestore::index_table_sb >&& sb) {
39-
auto id = sb->parent_uuid; // parent uuid is the volume id;
45+
auto pid_str = boost::uuids::to_string(sb->parent_uuid); // parent_uuid is the volume id
4046
{
41-
auto lg = std::scoped_lock(vol_lock_);
42-
auto it = vol_map_.find(id);
43-
DEBUG_ASSERT(it != vol_map_.end(), "volume id: {} not exists in recovery path, not expected!",
44-
boost::uuids::to_string(id));
47+
auto lg = std::scoped_lock(index_lock_);
48+
index_cfg_t cfg(homestore::hs()->index_service().node_size());
49+
cfg.m_leaf_node_type = homestore::btree_node_type::PREFIX;
50+
cfg.m_int_node_type = homestore::btree_node_type::PREFIX;
4551

46-
return it->second->init_index_table(true, std::move(sb));
52+
LOGI("Recovering index table for index_uuid: {}, parent_uuid: {}", boost::uuids::to_string(sb->uuid), pid_str);
53+
auto tbl = std::make_shared< VolumeIndexTable >(std::move(sb), cfg);
54+
idx_tbl_map_.emplace(pid_str, tbl);
55+
return tbl;
4756
}
4857
}
4958

0 commit comments

Comments
 (0)