mirror of
https://github.com/urbit/shrub.git
synced 2024-12-26 13:31:36 +03:00
Various fixes and cleanups
This commit is contained in:
parent
99532b3f2f
commit
607c83d683
49
v/raft.c
49
v/raft.c
@ -168,12 +168,18 @@ _raft_promote(u2_raft* raf_u)
|
|||||||
else {
|
else {
|
||||||
c3_i sas_i;
|
c3_i sas_i;
|
||||||
|
|
||||||
uL(fprintf(uH, "raft: promoting to leader\n"));
|
|
||||||
if ( 1 == raf_u->pop_w ) {
|
if ( 1 == raf_u->pop_w ) {
|
||||||
|
uL(fprintf(uH, "raft: -> lead\n"));
|
||||||
raf_u->typ_e = u2_raty_lead;
|
raf_u->typ_e = u2_raty_lead;
|
||||||
|
// TODO boot in multiuser mode
|
||||||
|
u2_sist_boot();
|
||||||
|
if ( u2_no == u2_Host.ops_u.bat ) {
|
||||||
|
u2_lo_lead(u2A);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c3_assert(u2_raty_cand == raf_u->typ_e);
|
c3_assert(u2_raty_cand == raf_u->typ_e);
|
||||||
|
uL(fprintf(uH, "raft: cand -> lead\n"));
|
||||||
raf_u->typ_e = u2_raty_lead;
|
raf_u->typ_e = u2_raty_lead;
|
||||||
|
|
||||||
sas_i = uv_timer_stop(&raf_u->tim_u);
|
sas_i = uv_timer_stop(&raf_u->tim_u);
|
||||||
@ -182,14 +188,6 @@ _raft_promote(u2_raft* raf_u)
|
|||||||
c3_assert(0 == sas_i);
|
c3_assert(0 == sas_i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO */
|
|
||||||
if ( 1 == raf_u->pop_w ) {
|
|
||||||
u2_sist_boot();
|
|
||||||
if ( u2_no == u2_Host.ops_u.bat ) {
|
|
||||||
u2_lo_lead(u2A);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _raft_demote(): demote to follower.
|
/* _raft_demote(): demote to follower.
|
||||||
@ -197,18 +195,27 @@ _raft_promote(u2_raft* raf_u)
|
|||||||
static void
|
static void
|
||||||
_raft_demote(u2_raft* raf_u)
|
_raft_demote(u2_raft* raf_u)
|
||||||
{
|
{
|
||||||
if ( u2_raty_lead == raf_u->typ_e ) {
|
u2_raty typ_e = raf_u->typ_e;
|
||||||
uL(fprintf(uH, "raft: demoting leader\n"));
|
|
||||||
/* TODO just start dropping events */
|
raf_u->vog_c = 0;
|
||||||
u2_lo_bail(u2A);
|
u2_sist_nil("vote");
|
||||||
|
raf_u->vot_w = 0;
|
||||||
|
raf_u->typ_e = u2_raty_foll;
|
||||||
|
|
||||||
|
if ( u2_raty_lead == typ_e ) {
|
||||||
|
c3_i sas_i;
|
||||||
|
|
||||||
|
uL(fprintf(uH, "raft: lead -> foll\n"));
|
||||||
|
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,
|
||||||
|
_raft_election_rand(), 0);
|
||||||
|
c3_assert(0 == sas_i);
|
||||||
|
// TODO dump not-yet-committed events
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c3_assert(u2_raty_cand == raf_u->typ_e);
|
c3_assert(u2_raty_cand == typ_e);
|
||||||
uL(fprintf(uH, "raft: demoting to follower\n"));
|
uL(fprintf(uH, "raft: cand -> foll\n"));
|
||||||
raf_u->vog_c = 0;
|
|
||||||
u2_sist_nil("vote");
|
|
||||||
raf_u->vot_w = 0;
|
|
||||||
raf_u->typ_e = u2_raty_foll;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1286,7 +1293,7 @@ _raft_time_cb(uv_timer_t* tim_u, c3_i sas_i)
|
|||||||
c3_assert(0);
|
c3_assert(0);
|
||||||
}
|
}
|
||||||
case u2_raty_foll: {
|
case u2_raty_foll: {
|
||||||
uL(fprintf(uH, "raft: promoting to candidate\n"));
|
uL(fprintf(uH, "raft: foll -> cand\n"));
|
||||||
raf_u->typ_e = u2_raty_cand;
|
raf_u->typ_e = u2_raty_cand;
|
||||||
// continue to cand
|
// continue to cand
|
||||||
}
|
}
|
||||||
@ -1306,7 +1313,7 @@ _raft_time_cb(uv_timer_t* tim_u, c3_i sas_i)
|
|||||||
static void
|
static void
|
||||||
_raft_foll_init(u2_raft* raf_u)
|
_raft_foll_init(u2_raft* raf_u)
|
||||||
{
|
{
|
||||||
uL(fprintf(uH, "raft: starting follower\n"));
|
uL(fprintf(uH, "raft: none -> foll\n"));
|
||||||
raf_u->typ_e = u2_raty_foll;
|
raf_u->typ_e = u2_raty_foll;
|
||||||
|
|
||||||
// Initialize and count peers.
|
// Initialize and count peers.
|
||||||
|
Loading…
Reference in New Issue
Block a user