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
fab7d434
Commit
fab7d434
authored
May 17, 2018
by
Willem Thiart
Browse files
Fix raft_periodic: raft_apply_all error handling
parent
f87df1dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/raft_server.c
View file @
fab7d434
...
@@ -234,7 +234,6 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
...
@@ -234,7 +234,6 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
if
(
me
->
request_timeout
<=
me
->
timeout_elapsed
)
if
(
me
->
request_timeout
<=
me
->
timeout_elapsed
)
raft_send_appendentries_all
(
me_
);
raft_send_appendentries_all
(
me_
);
}
}
else
if
(
me
->
election_timeout_rand
<=
me
->
timeout_elapsed
&&
else
if
(
me
->
election_timeout_rand
<=
me
->
timeout_elapsed
&&
/* Don't become the leader when building snapshots or bad things will
/* Don't become the leader when building snapshots or bad things will
* happen when we get a client request */
* happen when we get a client request */
...
@@ -253,7 +252,7 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
...
@@ -253,7 +252,7 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
!
raft_snapshot_is_in_progress
(
me_
))
!
raft_snapshot_is_in_progress
(
me_
))
{
{
int
e
=
raft_apply_all
(
me_
);
int
e
=
raft_apply_all
(
me_
);
if
(
-
1
!=
e
)
if
(
0
!=
e
)
return
e
;
return
e
;
}
}
...
...
tests/test_server.c
View file @
fab7d434
...
@@ -43,6 +43,16 @@ int __raft_applylog(
...
@@ -43,6 +43,16 @@ int __raft_applylog(
return
0
;
return
0
;
}
}
int
__raft_applylog_shutdown
(
raft_server_t
*
raft
,
void
*
udata
,
raft_entry_t
*
ety
,
int
idx
)
{
return
RAFT_ERR_SHUTDOWN
;
}
int
__raft_send_requestvote
(
raft_server_t
*
raft
,
int
__raft_send_requestvote
(
raft_server_t
*
raft
,
void
*
udata
,
void
*
udata
,
raft_node_t
*
node
,
raft_node_t
*
node
,
...
@@ -440,6 +450,37 @@ void TestRaft_server_increment_lastApplied_when_lastApplied_lt_commitidx(
...
@@ -440,6 +450,37 @@ void TestRaft_server_increment_lastApplied_when_lastApplied_lt_commitidx(
CuAssertIntEquals
(
tc
,
1
,
raft_get_last_applied_idx
(
r
));
CuAssertIntEquals
(
tc
,
1
,
raft_get_last_applied_idx
(
r
));
}
}
void
TestRaft_user_applylog_error_propogates_to_periodic
(
CuTest
*
tc
)
{
raft_cbs_t
funcs
=
{
.
persist_term
=
__raft_persist_term
,
.
applylog
=
__raft_applylog_shutdown
,
};
void
*
r
=
raft_new
();
raft_set_callbacks
(
r
,
&
funcs
,
NULL
);
/* must be follower */
raft_set_state
(
r
,
RAFT_STATE_FOLLOWER
);
raft_set_current_term
(
r
,
1
);
raft_set_last_applied_idx
(
r
,
0
);
/* need at least one entry */
raft_entry_t
ety
=
{};
ety
.
term
=
1
;
ety
.
id
=
1
;
ety
.
data
.
buf
=
"aaa"
;
ety
.
data
.
len
=
3
;
raft_append_entry
(
r
,
&
ety
);
raft_set_commit_idx
(
r
,
1
);
/* let time lapse */
CuAssertIntEquals
(
tc
,
RAFT_ERR_SHUTDOWN
,
raft_periodic
(
r
,
1
));
CuAssertIntEquals
(
tc
,
1
,
raft_get_last_applied_idx
(
r
));
}
void
TestRaft_server_apply_entry_increments_last_applied_idx
(
CuTest
*
tc
)
void
TestRaft_server_apply_entry_increments_last_applied_idx
(
CuTest
*
tc
)
{
{
raft_cbs_t
funcs
=
{
raft_cbs_t
funcs
=
{
...
...
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