Unverified Commit 0f2f98bc authored by Ozan Tezcan's avatar Ozan Tezcan Committed by GitHub
Browse files

Check if the node is leader inside raft_get_index_to_sync() (#85)

parent d718d2c0
......@@ -1550,7 +1550,7 @@ raft_index_t raft_get_num_snapshottable_logs(raft_server_t* me_);
* another thread. Also, users should call raft_flush() often to update
* persisted log index and to send new appendentries messages.
*
* Example :
* Example:
*
* void server_loop() {
* while (1) {
......@@ -1587,6 +1587,10 @@ int raft_set_auto_flush(raft_server_t* me, int flush);
* This function is only useful when auto flush is disabled. Same index will be
* reported once.
*
* If the node is not the leader, it returns zero. For followers, disk flush is
* synchronous. sync() callback is called when an appendentries message
* received. So, this function does not makes sense if the node is a follower.
*
* @param[in] raft The Raft server
* @return entry index need to be written to the disk.
* '0' if there is no new entry to write to the disk
......
......@@ -2159,10 +2159,11 @@ static int raft_update_commit_idx(raft_server_t* me_)
raft_index_t raft_get_index_to_sync(raft_server_t *me_)
{
raft_server_private_t* me = (raft_server_private_t*) me_;
raft_index_t idx = raft_get_current_idx(me_);
if (me->next_sync_index > idx)
if (!raft_is_leader(me_) || idx < me->next_sync_index) {
return 0;
}
me->next_sync_index = idx + 1;
return idx;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment