Skip to content

Commit 696849c

Browse files
authored
Issue 90: wire in discover_svc_id to HomeBlk's Superblk and its recovery (#91)
* Issue 90: wire in discover_svc_id * change to base info log for default visability
1 parent db2ae04 commit 696849c

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
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.15"
12+
version = "1.0.15"
1313
homepage = "https://github.com/eBay/HomeBlocks"
1414
description = "Block Store built on HomeStore"
1515
topics = ("ebay")

src/include/homeblks/home_blks.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class HomeBlocksApplication {
5959
virtual uint64_t app_mem_size() const = 0;
6060

6161
// Callback made after determining if a SvcId exists or not during initialization, will consume response
62-
virtual peer_id_t discover_svcid(std::optional< peer_id_t > const& found) const = 0;
62+
virtual std::optional< peer_id_t > discover_svc_id(std::optional< peer_id_t > const& found) const = 0;
6363
};
6464

6565
struct HomeBlocksStats {

src/lib/homeblks_impl.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
*
1515
*********************************************************************************/
1616
#include <algorithm>
17-
17+
#include <boost/uuid/uuid.hpp>
18+
#include <boost/uuid/nil_generator.hpp>
1819
#include <iomgr/io_environment.hpp>
1920
#include <homestore/homestore.hpp>
2021
#include <homestore/replication_service.hpp>
@@ -119,8 +120,8 @@ class HBReplApp : public homestore::ReplApplication {
119120

120121
homestore::replica_id_t get_my_repl_id() const override { return hb_->our_uuid(); }
121122

122-
void destroy_repl_dev_listener(homestore::group_id_t) override {
123-
LOGERROR("destroy_repl_dev_listener Unimplimented");
123+
void destroy_repl_dev_listener(homestore::group_id_t gid) override {
124+
LOGI("Destroying repl dev listener for group_id {}", boost::uuids::to_string(gid));
124125
}
125126

126127
private:
@@ -182,7 +183,11 @@ void HomeBlocksImpl::init_homestore() {
182183
.start(hs_input_params{.devices = device_info, .app_mem_size = app_mem_size},
183184
[this]() { register_metablk_cb(); });
184185
if (need_format) {
185-
LOGI("We are starting for the first time. Formatting HomeStore. ");
186+
auto ret = app->discover_svc_id(std::nullopt);
187+
DEBUG_ASSERT(ret.has_value(), "UUID should be generated by application.");
188+
our_uuid_ = ret.value();
189+
LOGINFO("We are starting for the first time on svc_id: [{}]. Formatting HomeStore. ",
190+
boost::uuids::to_string(our_uuid()));
186191
if (has_data_dev && has_fast_dev) {
187192
// NOTE: chunk_size, num_chunks only has to specify one, can be deduced from each other.
188193
homestore::hs()->format_and_start({
@@ -216,6 +221,12 @@ void HomeBlocksImpl::init_homestore() {
216221
}
217222
// repl_app->on_repl_devs_init_completed();
218223
superblk_init();
224+
} else {
225+
// we are starting on an existing system;
226+
DEBUG_ASSERT(our_uuid() != boost::uuids::nil_uuid(), "UUID should be recovered from HB superblock!");
227+
// now callback to application to nofity the uuid so that we are treated as an existing system;
228+
app->discover_svc_id(our_uuid());
229+
LOGINFO("We are starting on [{}].", boost::uuids::to_string(our_uuid_));
219230
}
220231

221232
recovery_done_ = true;
@@ -228,6 +239,7 @@ void HomeBlocksImpl::superblk_init() {
228239
sb_->version = HB_SB_VER;
229240
sb_->boot_cnt = 0;
230241
sb_->init_flag(0);
242+
sb_->svc_id = our_uuid_;
231243
sb_.write();
232244
}
233245

@@ -247,6 +259,10 @@ void HomeBlocksImpl::on_hb_meta_blk_found(sisl::byte_view const& buf, void* cook
247259

248260
++sb_->boot_cnt;
249261

262+
our_uuid_ = sb_->svc_id;
263+
264+
LOGI("HomeBlks superblock loaded, boot_cnt: {}, svc_id: {}", sb_->boot_cnt, boost::uuids::to_string(our_uuid_));
265+
250266
// avoid doing sb meta blk write in callback which will cause deadlock;
251267
// the 1st CP should flush all dirty SB before taking traffic;
252268
}

src/lib/homeblks_impl.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab
3636
uint32_t version;
3737
uint32_t flag;
3838
uint64_t boot_cnt;
39+
peer_id_t svc_id;
3940

4041
void init_flag(uint32_t f) { flag = f; }
4142
void set_flag(uint32_t bit) { flag |= bit; }
@@ -67,6 +68,7 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab
6768

6869
bool recovery_done_{false};
6970
superblk< homeblks_sb_t > sb_;
71+
peer_id_t our_uuid_;
7072

7173
public:
7274
explicit HomeBlocksImpl(std::weak_ptr< HomeBlocksApplication >&& application);
@@ -84,10 +86,7 @@ class HomeBlocksImpl : public HomeBlocks, public VolumeManager, public std::enab
8486
HomeBlocksStats get_stats() const final;
8587
iomgr::drive_type data_drive_type() const final;
8688

87-
peer_id_t our_uuid() const final {
88-
// not expected to be called;
89-
return peer_id_t{};
90-
}
89+
peer_id_t our_uuid() const final { return our_uuid_; }
9190

9291
/// VolumeManager
9392
NullAsyncResult create_volume(VolumeInfo&& vol_info) final;

src/lib/volume/tests/test_common.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <sisl/settings/settings.hpp>
2626
#include <boost/uuid/string_generator.hpp>
2727
#include <boost/uuid/nil_generator.hpp>
28+
#include <boost/uuid/random_generator.hpp>
2829
#include <chrono>
2930
#include <iostream>
3031
#include <thread>
@@ -82,7 +83,9 @@ class HBTestHelper {
8283
return devs;
8384
}
8485

85-
peer_id_t discover_svcid(std::optional< peer_id_t > const&) const override { return helper_.svc_id(); }
86+
std::optional< peer_id_t > discover_svc_id(std::optional< peer_id_t > const&) const override {
87+
return helper_.svc_id();
88+
}
8689

8790
uint64_t app_mem_size() const override {
8891
// return SISL_OPTIONS["app_mem_size"].as< uint64_t >();
@@ -99,7 +102,7 @@ class HBTestHelper {
99102
sisl::logging::SetLogPattern("[%D %T%z] [%^%L%$] [%n] [%t] %v");
100103

101104
// init svc_id_
102-
svc_id_ = boost::uuids::nil_uuid();
105+
svc_id_ = boost::uuids::random_generator()();
103106

104107
// init device list
105108
init_dev_list(true /*init_device*/);

0 commit comments

Comments
 (0)