-
Notifications
You must be signed in to change notification settings - Fork 240
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
support setting raft server init options and raft callback in raft_launcher::init() #147
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sheepgrass , some minor comments.
include/libnuraft/launcher.hxx
Outdated
@@ -45,7 +47,9 @@ public: | |||
ptr<logger> lg, | |||
int port_number, | |||
const asio_service::options& asio_options, | |||
const raft_params& params); | |||
const raft_params& params, | |||
const raft_server::init_options opt = raft_server::init_options(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please use reference?
const raft_server::init_options& opt = raft_server::init_options()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
Actually, I was just copied from your unit test case :p
NuRaft/tests/unit/raft_package_fake.hxx
Lines 51 to 54 in 7501788
void initServer(raft_params* given_params = nullptr, | |
const raft_server::init_options opt = | |
raft_server::init_options(), | |
cb_func::func_type raft_callback = nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch, it also needs to be fixed. Thanks :)
src/launcher.cxx
Outdated
const raft_params& params_given) | ||
const raft_params& params_given, | ||
const raft_server::init_options opt, | ||
cb_func::func_type raft_callback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in the previous PR, I'd like to suggest you to move cb_func::func_type raft_callback
inside raft_server::init_options
like this:
struct init_options {
// ...
bool skip_initial_election_timeout_;
cb_func::func_type raft_callback_;
};
and invoke ctx->set_cb_func(...)
inside the constructor of raft_server
. Then launcher doesn't need to call set_cb_func
, thus we can get benefit for both launcher and raft_server. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry that I didn't notice you mentioned about moving it to raft_server constructor. I will make the change.
Actually, for this change, I am also taken reference to your unit test case:
NuRaft/tests/unit/raft_package_fake.hxx
Lines 85 to 90 in 7501788
ctx = new context( sMgr, sm, listener, myLog, | |
rpcCliFactory, scheduler, params ); | |
if (raft_callback) { | |
ctx->set_cb_func(raft_callback); | |
} | |
raftServer = cs_new<raft_server>(ctx, opt); |
…nc() in raft_server constructor
support setting raft server init options and raft callback in raft_launcher::init()