From 53fafd25fdf23ed234fc0a4464ccef0f9902077a Mon Sep 17 00:00:00 2001 From: Steven Dee Date: Thu, 6 Mar 2014 16:04:52 -0800 Subject: [PATCH] update -> note, and call it --- v/raft.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/v/raft.c b/v/raft.c index 35eda9a23..5d6479a8b 100644 --- a/v/raft.c +++ b/v/raft.c @@ -181,10 +181,10 @@ _raft_demote(u2_raft* raf_u) } } -/* _raft_update_term(): note an updated term. +/* _raft_note_term(): note a term from the network, demoting if it is newer. */ static void -_raft_update_term(u2_raft* raf_u, c3_w tem_w) +_raft_note_term(u2_raft* raf_u, c3_w tem_w) { if ( raf_u->tem_w < tem_w ) { uL(fprintf(uH, "raft: got term from network: %d\n", tem_w)); @@ -243,21 +243,19 @@ static void _raft_do_rest(u2_rcon* ron_u, const u2_rmsg* msg_u) { u2_raft* raf_u = ron_u->raf_u; - c3_i sas_i; - sas_i = uv_timer_stop(&raf_u->tim_u); - c3_assert(0 == sas_i); - sas_i = uv_timer_start(&raf_u->tim_u, &_raft_time_cb, - 150 + _raft_election_rand(), 0); - c3_assert(0 == sas_i); + if ( u2_raty_cand == raf_u->typ_e || u2_raty_foll == raf_u->typ_e ) { + c3_i sas_i; - if ( msg_u->tem_w > raf_u->tem_w ) { - uL(fprintf(uH, "raft: got term %d from network\n", msg_u->tem_w)); - raf_u->tem_w = msg_u->tem_w; - raf_u->vog_c = 0; - raf_u->vot_w = 0; + sas_i = uv_timer_stop(&raf_u->tim_u); + c3_assert(0 == sas_i); + sas_i = uv_timer_start(&raf_u->tim_u, &_raft_time_cb, + 150 + _raft_election_rand(), 0); + c3_assert(0 == sas_i); } + _raft_rest_name(ron_u, msg_u->rest.nam_c); + _raft_note_term(raf_u, msg_u->tem_w); } /* _raft_do_apen(): Handle incoming AppendEntries. @@ -358,7 +356,7 @@ _raft_do_rasp(u2_rcon* ron_u, u2_rmsg* msg_u) } } - _raft_update_term(raf_u, msg_u->tem_w); + _raft_note_term(raf_u, msg_u->tem_w); ron_u->out_u = req_u->nex_u; if ( 0 == req_u->nex_u ) {