Skip to content

Commit

Permalink
Simplify the raft_event callback for mesg_state_mgr.
Browse files Browse the repository at this point in the history
Existing implementation was clumsy and incorrect. Simplify.
  • Loading branch information
szmyd committed Dec 12, 2024
1 parent e878a48 commit a0aca42
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
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;
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

0 comments on commit a0aca42

Please sign in to comment.