Commit 05608a3b authored by Willem Thiart's avatar Willem Thiart
Browse files

Prevent commit_idx increasing on minority

parent b7324a87
......@@ -210,7 +210,8 @@ int raft_recv_appendentries_response(raft_server_t* me_,
int point = r->current_idx;
int i;
for (i = 0; i < me->num_nodes; i++) /* Check others */
if (i != me->nodeid && point <= raft_node_get_match_idx(node))
if (i != me->nodeid && point <=
raft_node_get_match_idx(raft_get_node(me_, i)))
votes++;
if (me->num_nodes / 2 < votes && raft_get_commit_idx(me_) < point)
raft_set_commit_idx(me_, point);
......
......@@ -1717,13 +1717,12 @@ void TestRaft_leader_recv_appendentries_response_increase_commit_idx_when_majori
aer.current_idx = 1;
aer.first_idx = 1;
raft_recv_appendentries_response(r, 0, &aer);
CuAssertIntEquals(tc, 0, raft_get_commit_idx(r));
raft_recv_appendentries_response(r, 1, &aer);
/* leader will now have majority followers who have appended this log */
CuAssertTrue(tc, 0 != raft_get_commit_idx(r));
CuAssertTrue(tc, 2 != raft_get_commit_idx(r));
CuAssertTrue(tc, 1 == raft_get_commit_idx(r));
CuAssertIntEquals(tc, 1, raft_get_commit_idx(r));
raft_periodic(r, 1);
CuAssertTrue(tc, 1 == raft_get_last_applied_idx(r));
CuAssertIntEquals(tc, 1, raft_get_last_applied_idx(r));
/* SECOND entry log application */
/* send appendentries -
......@@ -1736,6 +1735,7 @@ void TestRaft_leader_recv_appendentries_response_increase_commit_idx_when_majori
aer.current_idx = 2;
aer.first_idx = 2;
raft_recv_appendentries_response(r, 0, &aer);
CuAssertIntEquals(tc, 1, raft_get_commit_idx(r));
raft_recv_appendentries_response(r, 1, &aer);
/* leader will now have majority followers who have appended this log */
CuAssertIntEquals(tc, 2, raft_get_commit_idx(r));
......
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