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
126127private:
@@ -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}
0 commit comments