Skip to content

Commit

Permalink
DAOS-333 server: Don't remove later entries for matching AEs
Browse files Browse the repository at this point in the history
If an AE request's previous entry matches the follower's, then the
follower doesn't need to truncate its log at prev_log_idx. When the
follower checks if the other entries in the AE request are consistent
with its local ones, it already takes care of truncating at any
inconsistency. If any later entries not covered by this AE request are
inconsistent, future AE requests shall truncate them.

Signed-off-by: Li Wei <wei.g.li@intel.com>
  • Loading branch information
liw authored and willemt committed Nov 21, 2017
1 parent e33da84 commit 77fb611
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
14 changes: 2 additions & 12 deletions src/raft_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,11 @@ int raft_recv_appendentries(
}
}

r->current_idx = ae->prev_log_idx;

/* 3. If an existing entry conflicts with a new one (same index
but different terms), delete the existing entry and all that
follow it (§5.3) */
if (0 < ae->prev_log_idx && ae->prev_log_idx + 1 < raft_get_current_idx(me_))
{
/* Heartbeats shouldn't cause logs to be deleted. Heartbeats might be
* sent before the leader received the last appendentries response */
if (ae->n_entries != 0 &&
/* this is an old out-of-order appendentry message */
me->commit_idx < ae->prev_log_idx + 1)
raft_delete_entry_from_idx(me_, ae->prev_log_idx + 1);
}

r->current_idx = ae->prev_log_idx;

int i;
for (i = 0; i < ae->n_entries; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ void TestRaft_follower_recv_appendentries_delete_entries_if_conflict_with_new_en
CuAssertTrue(tc, !strncmp(ety_appended->data.buf, str4, 3));
}

void TestRaft_follower_recv_appendentries_delete_entries_if_current_idx_greater_than_prev_log_idx(
void TestRaft_follower_recv_appendentries_delete_entries_if_conflict_with_new_entries_greater_than_prev_log_idx(
CuTest * tc)
{
raft_cbs_t funcs = {
Expand Down

0 comments on commit 77fb611

Please sign in to comment.