braft icon indicating copy to clipboard operation
braft copied to clipboard

Can `_node->is_leader()` be used?

Open kishorenc opened this issue 5 years ago • 1 comments

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?

kishorenc avatar May 04 '20 14:05 kishorenc

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

zergvszerg avatar May 14 '20 07:05 zergvszerg