Skip to content

Commit

Permalink
Revert "Change: code now assumes callbacks are provided"
Browse files Browse the repository at this point in the history
This reverts commit c3443aa. Test
changes are left intact.
  • Loading branch information
liw authored and willemt committed Nov 21, 2017
1 parent 51e049f commit e33da84
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/raft_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ int raft_send_requestvote(raft_server_t* me_, raft_node_t* node)
{
raft_server_private_t* me = (raft_server_private_t*)me_;
msg_requestvote_t rv;
int e = 0;

assert(node);
assert(node != me->node);
Expand All @@ -693,8 +694,9 @@ int raft_send_requestvote(raft_server_t* me_, raft_node_t* node)
rv.last_log_idx = raft_get_current_idx(me_);
rv.last_log_term = raft_get_last_log_term(me_);
rv.candidate_id = raft_get_nodeid(me_);
assert(me->cb.send_requestvote);
return me->cb.send_requestvote(me_, me->udata, node, &rv);
if (me->cb.send_requestvote)
e = me->cb.send_requestvote(me_, me->udata, node, &rv);
return e;
}

int raft_append_entry(raft_server_t* me_, raft_entry_t* ety)
Expand Down Expand Up @@ -725,10 +727,12 @@ int raft_apply_entry(raft_server_t* me_)
me->last_applied_idx, ety->id, ety->data.len);

me->last_applied_idx++;
assert(me->cb.applylog);
int e = me->cb.applylog(me_, me->udata, ety, me->last_applied_idx - 1);
if (RAFT_ERR_SHUTDOWN == e)
return RAFT_ERR_SHUTDOWN;
if (me->cb.applylog)
{
int e = me->cb.applylog(me_, me->udata, ety, me->last_applied_idx - 1);
if (RAFT_ERR_SHUTDOWN == e)
return RAFT_ERR_SHUTDOWN;
}

/* Membership Change: confirm connection with cluster */
if (RAFT_LOGTYPE_ADD_NODE == ety->type)
Expand Down Expand Up @@ -759,6 +763,9 @@ int raft_send_appendentries(raft_server_t* me_, raft_node_t* node)
assert(node);
assert(node != me->node);

if (!(me->cb.send_appendentries))
return -1;

msg_appendentries_t ae = {};
ae.term = me->current_term;
ae.leader_commit = raft_get_commit_idx(me_);
Expand Down Expand Up @@ -786,7 +793,6 @@ int raft_send_appendentries(raft_server_t* me_, raft_node_t* node)
ae.prev_log_idx,
ae.prev_log_term);

assert(me->cb.send_appendentries);
return me->cb.send_appendentries(me_, me->udata, node, &ae);
}

Expand Down Expand Up @@ -904,8 +910,8 @@ void raft_vote_for_nodeid(raft_server_t* me_, const int nodeid)
raft_server_private_t* me = (raft_server_private_t*)me_;

me->voted_for = nodeid;
assert(me->cb.persist_vote);
me->cb.persist_vote(me_, me->udata, nodeid);
if (me->cb.persist_vote)
me->cb.persist_vote(me_, me->udata, nodeid);
}

int raft_msg_entry_response_committed(raft_server_t* me_,
Expand Down

0 comments on commit e33da84

Please sign in to comment.