From a37777097d506b81a4530cbc21be279d2184af19 Mon Sep 17 00:00:00 2001 From: Jie Yao Date: Tue, 30 Jan 2024 23:54:34 -0700 Subject: [PATCH] using shared --- src/include/homestore/replication/repl_dev.h | 6 +++--- src/lib/replication/service/generic_repl_svc.cpp | 4 ++-- src/lib/replication/service/raft_repl_service.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/include/homestore/replication/repl_dev.h b/src/include/homestore/replication/repl_dev.h index 28b494f0f..0da767ef9 100644 --- a/src/include/homestore/replication/repl_dev.h +++ b/src/include/homestore/replication/repl_dev.h @@ -102,8 +102,8 @@ class ReplDevListener { public: virtual ~ReplDevListener() = default; - void set_repl_dev(ReplDev* rdev) { m_repl_dev = rdev; } - virtual ReplDev* repl_dev() { return m_repl_dev; } + void set_repl_dev(shared< ReplDev > rdev) { m_repl_dev = rdev; } + virtual shared< ReplDev > repl_dev() { return m_repl_dev.lock(); } /// @brief Called when the log entry has been committed in the replica set. /// @@ -184,7 +184,7 @@ class ReplDevListener { virtual void on_replica_stop() = 0; private: - ReplDev* m_repl_dev; + std::weak_ptr< ReplDev > m_repl_dev; }; class ReplDev { diff --git a/src/lib/replication/service/generic_repl_svc.cpp b/src/lib/replication/service/generic_repl_svc.cpp index 451c355dc..240c82623 100644 --- a/src/lib/replication/service/generic_repl_svc.cpp +++ b/src/lib/replication/service/generic_repl_svc.cpp @@ -108,7 +108,7 @@ AsyncReplResult< shared< ReplDev > > SoloReplService::create_repl_dev(group_id_t auto rdev = std::make_shared< SoloReplDev >(std::move(rd_sb), false /* load_existing */); auto listener = m_repl_app->create_repl_dev_listener(group_id); - listener->set_repl_dev(rdev.get()); + listener->set_repl_dev(rdev); rdev->attach_listener(std::move(listener)); { @@ -133,7 +133,7 @@ void SoloReplService::load_repl_dev(sisl::byte_view const& buf, void* meta_cooki auto rdev = std::make_shared< SoloReplDev >(std::move(rd_sb), true /* load_existing */); auto listener = m_repl_app->create_repl_dev_listener(group_id); - listener->set_repl_dev(rdev.get()); + listener->set_repl_dev(rdev); rdev->attach_listener(std::move(listener)); { diff --git a/src/lib/replication/service/raft_repl_service.cpp b/src/lib/replication/service/raft_repl_service.cpp index 960354a1f..dad370578 100644 --- a/src/lib/replication/service/raft_repl_service.cpp +++ b/src/lib/replication/service/raft_repl_service.cpp @@ -160,7 +160,7 @@ void RaftReplService::raft_group_config_found(sisl::byte_view const& buf, void* auto rdev = std::dynamic_pointer_cast< RaftReplDev >(*v); auto listener = m_repl_app->create_repl_dev_listener(group_id); - listener->set_repl_dev(rdev.get()); + listener->set_repl_dev(rdev); rdev->attach_listener(std::move(listener)); rdev->use_config(std::move(group_config)); } @@ -194,7 +194,7 @@ shared< nuraft_mesg::mesg_state_mgr > RaftReplService::create_state_mgr(int32_t // Attach the listener to the raft auto listener = m_repl_app->create_repl_dev_listener(group_id); - listener->set_repl_dev(rdev.get()); + listener->set_repl_dev(rdev); rdev->attach_listener(std::move(listener)); // Add the repl dev to the map