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
Willemt Raft
Commits
4ddc2738
Unverified
Commit
4ddc2738
authored
Oct 06, 2018
by
Willem
Committed by
GitHub
Oct 06, 2018
Browse files
Merge pull request #97 from yossigo/fix/ae-failure-handling
AE error response not properly handled.
parents
0e755635
f8236e02
Changes
2
Show whitespace changes
Inline
Side-by-side
src/raft_server.c
View file @
4ddc2738
...
...
@@ -311,8 +311,7 @@ int raft_recv_appendentries_response(raft_server_t* me_,
raft_index_t
next_idx
=
raft_node_get_next_idx
(
node
);
assert
(
0
<
next_idx
);
/* Stale response -- ignore */
assert
(
match_idx
<=
next_idx
-
1
);
if
(
match_idx
==
next_idx
-
1
)
if
(
r
->
current_idx
<
match_idx
)
return
0
;
if
(
r
->
current_idx
<
next_idx
-
1
)
raft_node_set_next_idx
(
node
,
min
(
r
->
current_idx
+
1
,
raft_get_current_idx
(
me_
)));
...
...
tests/test_snapshotting.c
View file @
4ddc2738
...
...
@@ -66,6 +66,16 @@ static int __raft_send_appendentries_capture(raft_server_t* raft,
return
0
;
}
static
int
__raft_send_snapshot_increment
(
raft_server_t
*
raft
,
void
*
udata
,
raft_node_t
*
node
)
{
int
*
counter
=
udata
;
(
*
counter
)
++
;
return
0
;
}
/* static raft_cbs_t generic_funcs = { */
/* .persist_term = __raft_persist_term, */
/* .persist_vote = __raft_persist_vote, */
...
...
@@ -735,3 +745,73 @@ void TestRaft_cancel_snapshot_restores_state(CuTest* tc)
CuAssertIntEquals
(
tc
,
2
,
raft_get_snapshot_last_idx
(
r
));
}
void
TestRaft_leader_sends_snapshot_if_log_was_compacted
(
CuTest
*
tc
)
{
raft_cbs_t
funcs
=
{
.
send_snapshot
=
__raft_send_snapshot_increment
,
.
send_appendentries
=
__raft_send_appendentries
};
int
send_snapshot_count
=
0
;
void
*
r
=
raft_new
();
raft_set_callbacks
(
r
,
&
funcs
,
&
send_snapshot_count
);
raft_node_t
*
node
;
raft_add_node
(
r
,
NULL
,
1
,
1
);
node
=
raft_add_node
(
r
,
NULL
,
2
,
0
);
raft_add_node
(
r
,
NULL
,
3
,
0
);
raft_set_state
(
r
,
RAFT_STATE_LEADER
);
raft_set_current_term
(
r
,
1
);
/* entry 1 */
char
*
str
=
"aaa"
;
raft_entry_t
ety
=
{};
ety
.
term
=
1
;
ety
.
id
=
1
;
ety
.
data
.
buf
=
str
;
ety
.
data
.
len
=
3
;
raft_append_entry
(
r
,
&
ety
);
/* entry 2 */
ety
.
term
=
1
;
ety
.
id
=
2
;
ety
.
data
.
buf
=
str
;
ety
.
data
.
len
=
3
;
raft_append_entry
(
r
,
&
ety
);
/* entry 3 */
ety
.
term
=
1
;
ety
.
id
=
3
;
ety
.
data
.
buf
=
str
;
ety
.
data
.
len
=
3
;
raft_append_entry
(
r
,
&
ety
);
CuAssertIntEquals
(
tc
,
3
,
raft_get_current_idx
(
r
));
/* compact entry 1 & 2 */
raft_set_commit_idx
(
r
,
2
);
CuAssertIntEquals
(
tc
,
0
,
raft_begin_snapshot
(
r
,
0
));
CuAssertIntEquals
(
tc
,
0
,
raft_end_snapshot
(
r
));
CuAssertIntEquals
(
tc
,
1
,
raft_get_log_count
(
r
));
/* at this point a snapshot should have been sent; we'll continue
* assuming the node was not available to get it.
*/
CuAssertIntEquals
(
tc
,
2
,
send_snapshot_count
);
send_snapshot_count
=
0
;
/* node wants an entry that was compacted */
raft_node_set_match_idx
(
node
,
1
);
raft_node_set_next_idx
(
node
,
2
);
msg_appendentries_response_t
aer
;
aer
.
term
=
1
;
aer
.
success
=
0
;
aer
.
current_idx
=
1
;
aer
.
first_idx
=
4
;
raft_recv_appendentries_response
(
r
,
node
,
&
aer
);
CuAssertIntEquals
(
tc
,
1
,
send_snapshot_count
);
}
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