From 77fb611736243a0c6e35993287c88e3d0a603fa0 Mon Sep 17 00:00:00 2001 From: Li Wei Date: Tue, 29 Aug 2017 11:07:34 +0800 Subject: [PATCH] DAOS-333 server: Don't remove later entries for matching AEs 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 --- src/raft_server.c | 14 ++------------ tests/test_server.c | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/raft_server.c b/src/raft_server.c index 83456824..b9c2962d 100644 --- a/src/raft_server.c +++ b/src/raft_server.c @@ -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++) { diff --git a/tests/test_server.c b/tests/test_server.c index 9024b666..9fdd2f5b 100644 --- a/tests/test_server.c +++ b/tests/test_server.c @@ -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 = {