Commit fab7d434 authored by Willem Thiart's avatar Willem Thiart
Browse files

Fix raft_periodic: raft_apply_all error handling

parent f87df1dc
......@@ -234,7 +234,6 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
if (me->request_timeout <= me->timeout_elapsed)
raft_send_appendentries_all(me_);
}
else if (me->election_timeout_rand <= me->timeout_elapsed &&
/* Don't become the leader when building snapshots or bad things will
* happen when we get a client request */
......@@ -253,7 +252,7 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
!raft_snapshot_is_in_progress(me_))
{
int e = raft_apply_all(me_);
if (-1 != e)
if (0 != e)
return e;
}
......
......@@ -43,6 +43,16 @@ int __raft_applylog(
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,
void* udata,
raft_node_t* node,
......@@ -440,6 +450,37 @@ void TestRaft_server_increment_lastApplied_when_lastApplied_lt_commitidx(
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)
{
raft_cbs_t funcs = {
......
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