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

How to make cluster config persistent? #103

Closed
felipeasf opened this issue Feb 28, 2020 · 6 comments
Closed

How to make cluster config persistent? #103

felipeasf opened this issue Feb 28, 2020 · 6 comments

Comments

@felipeasf
Copy link

felipeasf commented Feb 28, 2020

Hello, how can I make the cluster config persistent? For example, if I have 3 servers instances online that are already part a cluster and all of them get offline at the same time. There is a way to make them reconnect to the same cluster? The first one to reconnect become master, and the others followers?
To achieve that, the only thing I need to do is implement the in_memory state_mgr.hxx file to save to the disk instead of use memory?

@greensky00
Copy link
Contributor

Hi @felipeasf
Yes, as we commented here

// Need to write to disk here, if want to make it durable.

you need to implement save_config and load_config, as well as save_state and read_state. Once those APIs are working, Raft server will automatically call them and reconstruct the last cluster info.

@felipeasf
Copy link
Author

Thanks for the answer @greensky00 !
I didn't know about that part of the calls being automatic. I got it working =)
Another question is: There is a way to know when a slave becomes a master?

@greensky00
Copy link
Contributor

You can register a callback function for hooking up a few events:

void set_cb_func(cb_func::func_type func) {

The event for becoming a leader is defined here:

BecomeLeader = 6,

@felipeasf
Copy link
Author

To register this callback I need the current context, right? As the context is created when the launcher.init function is called, how can I get the current context in order to set the callback?

@greensky00
Copy link
Contributor

context is given at the initialization of Raft server and then becomes read-only. You need to set your callback function at the init time.

And now I realized that if someone uses raft_launcher, there is no way to set the callback function. A simple workaround for now is writing your own init function.

Seems to me the API that setting the callback function should be exposed outside. Will fix that soon. Thanks.

@felipeasf
Copy link
Author

I wrote my own init function and is all good now!
Thanks for your kindly support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants