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

Can _node->is_leader() be used? #208

Open
kishorenc opened this issue May 4, 2020 · 1 comment
Open

Can _node->is_leader() be used? #208

kishorenc opened this issue May 4, 2020 · 1 comment

Comments

@kishorenc
Copy link
Contributor

The examples use a _leader_term variable to check if the current node is a leader:

https://github.com/baidu/braft/blob/master/example/counter/server.cpp#L153

Instead, can one use _node->is_leader()?

https://github.com/baidu/braft/blob/master/src/braft/raft.h#L619

What's the difference between these 2 different approaches?

@zergvszerg
Copy link

I'm guessing the big difference be that Node::is_leader() try to acquire a bthread_mutex_t before reading the |_state|, while the fsm(example::Counter) just use an atomic load

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