Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
RedisLabs Raft
Commits
9bdf41b5
Commit
9bdf41b5
authored
May 24, 2017
by
Willem Thiart
Browse files
Fixes #35
Avoid for loop to increase performance when tallying votes for committing.
parent
c3443aac
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/raft_server.c
View file @
9bdf41b5
...
...
@@ -279,27 +279,28 @@ int raft_recv_appendentries_response(raft_server_t* me_,
}
/* Update commit idx */
int votes = 1; /* include me */
int point = r->current_idx;
int i;
for (i = 0; i < me->num_nodes; i++)
if (point)
{
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)
raft_entry_t* ety = raft_get_entry_from_idx(me_, point);
if (raft_get_commit_idx(me_) < point && ety->term == me->current_term)
{
raft_entry_t* ety = raft_get_entry_from_idx(me_, match_idx);
if (ety->term == me->current_term && point <= match_idx)
votes++;
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]) &&
point <= raft_node_get_match_idx(me->nodes[i]))
{
votes++;
}
}
if (raft_get_num_voting_nodes(me_) / 2 < votes)
raft_set_commit_idx(me_, point);
}
}
if (raft_get_num_voting_nodes(me_) / 2 < votes && raft_get_commit_idx(me_) < point)
raft_set_commit_idx(me_, point);
/* Aggressively send remaining entries */
if (raft_get_entry_from_idx(me_, raft_node_get_next_idx(node)))
raft_send_appendentries(me_, node);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment