Commit 9bdf41b5 authored by Willem Thiart's avatar Willem Thiart
Browse files

Fixes #35

Avoid for loop to increase performance when tallying votes for
committing.
parent c3443aac
......@@ -279,26 +279,27 @@ int raft_recv_appendentries_response(raft_server_t* me_,
}
/* Update commit idx */
int votes = 1; /* include me */
int point = r->current_idx;
int i;
if (point)
{
raft_entry_t* ety = raft_get_entry_from_idx(me_, point);
if (raft_get_commit_idx(me_) < point && ety->term == me->current_term)
{
int i, votes = 1;
for (i = 0; i < me->num_nodes; i++)
{
if (me->node == me->nodes[i] || !raft_node_is_voting(me->nodes[i]))
continue;
int match_idx = raft_node_get_match_idx(me->nodes[i]);
if (0 < match_idx)
if (me->node != me->nodes[i] &&
raft_node_is_voting(me->nodes[i]) &&
point <= raft_node_get_match_idx(me->nodes[i]))
{
raft_entry_t* ety = raft_get_entry_from_idx(me_, match_idx);
if (ety->term == me->current_term && point <= match_idx)
votes++;
}
}
if (raft_get_num_voting_nodes(me_) / 2 < votes && raft_get_commit_idx(me_) < point)
if (raft_get_num_voting_nodes(me_) / 2 < votes)
raft_set_commit_idx(me_, point);
}
}
/* Aggressively send remaining entries */
if (raft_get_entry_from_idx(me_, raft_node_get_next_idx(node)))
......
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