Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the raft_event callback for mesg_state_mgr. #112

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class NuRaftMesgConan(ConanFile):
name = "nuraft_mesg"
version = "3.7.0"
version = "3.7.1"

homepage = "https://github.com/eBay/nuraft_mesg"
description = "A gRPC service for NuRAFT"
Expand Down
11 changes: 8 additions & 3 deletions include/nuraft_mesg/mesg_state_mgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ class mesg_state_mgr : public nuraft::state_mgr {
virtual void permanent_destroy() = 0;
virtual void leave() = 0;

virtual std::pair< bool, nuraft::cb_func::ReturnCode > handle_raft_event(nuraft::cb_func::Type,
nuraft::cb_func::Param*) {
return std::pair(false, nuraft::cb_func::ReturnCode::Ok);
/// TODO: Deprecated DO NOT USE
virtual std::pair< bool, nuraft::cb_func::ReturnCode > handle_raft_event(nuraft::cb_func::Type t,
nuraft::cb_func::Param* p) {
return std::pair(false, raft_event(t, p));
}

virtual nuraft::cb_func::ReturnCode raft_event(nuraft::cb_func::Type, nuraft::cb_func::Param*) {
return nuraft::cb_func::ReturnCode::Ok;
}

nuraft::cb_func::ReturnCode internal_raft_event_handler(group_id_t const& group_id, nuraft::cb_func::Type type,
Expand Down
16 changes: 9 additions & 7 deletions src/lib/manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ void ManagerImpl::register_mgr_type(group_type_t const& group_type, group_params
if (_state_mgr_types.end() == it) { LOGE("Could not register [group_type={}]", group_type); }
}

nuraft::cb_func::ReturnCode ManagerImpl::generic_raft_event_handler(group_id_t const& group_id,
nuraft::cb_func::Type type,
nuraft::cb_func::Param* param) {
void ManagerImpl::generic_raft_event_handler(group_id_t const& group_id,
nuraft::cb_func::Type type,
nuraft::cb_func::Param* param) {
auto const& my_id = param->myId;
auto const& leader_id = param->leaderId;
switch (type) {
Expand Down Expand Up @@ -171,7 +171,6 @@ nuraft::cb_func::ReturnCode ManagerImpl::generic_raft_event_handler(group_id_t c
default:
break;
};
return nuraft::cb_func::ReturnCode::Ok;
}

void ManagerImpl::exit_group(group_id_t const& group_id) {
Expand Down Expand Up @@ -388,9 +387,12 @@ void mesg_state_mgr::make_repl_ctx(grpc_server* server, std::shared_ptr< mesg_fa
nuraft::cb_func::ReturnCode mesg_state_mgr::internal_raft_event_handler(group_id_t const& group_id,
nuraft::cb_func::Type type,
nuraft::cb_func::Param* param) {
if (auto const [handled, ret] = handle_raft_event(type, param); handled) { return ret; }
if (auto sp = m_manager.lock(); sp) { return sp->generic_raft_event_handler(group_id, type, param); }
return nuraft::cb_func::Ok;
// Have we shutdown?
if (auto sp = m_manager.lock(); sp)
sp->generic_raft_event_handler(group_id, type, param);
else
return nuraft::cb_func::ReturnNull;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: pls add a log here(before line 394) to print out the ManagerImpl instance is destroyed(or shutdown), which will be helpful for debug

return handle_raft_event(type, param).second;
}

std::shared_ptr< Manager > init_messaging(Manager::Params const& p, std::weak_ptr< MessagingApplication > w,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/manager_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class ManagerImpl : public Manager, public std::enable_shared_from_this< Manager
nuraft::cmd_result_code group_init(int32_t const srv_id, group_id_t const& group_id, group_type_t const& group_type,
nuraft::context*& ctx, std::shared_ptr< group_metrics > metrics);
void start(bool and_data_svc);
nuraft::cb_func::ReturnCode generic_raft_event_handler(group_id_t const& group_id, nuraft::cb_func::Type type,
nuraft::cb_func::Param* param);
void generic_raft_event_handler(group_id_t const& group_id, nuraft::cb_func::Type type,
nuraft::cb_func::Param* param);

//
};
Expand Down
Loading