From d045f31f23cefd9f4d2a560de61626c8f8bc461c Mon Sep 17 00:00:00 2001 From: Steve Dee Date: Fri, 28 Feb 2014 14:52:00 -0800 Subject: [PATCH] Rejigger the event loop again --- include/v/vere.h | 16 ++++++++-------- v/loop.c | 15 +++++++++------ v/main.c | 5 +---- v/raft.c | 20 ++++++++++++++++---- v/sist.c | 1 - 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/include/v/vere.h b/include/v/vere.h index 07ad63585..f2798915a 100644 --- a/include/v/vere.h +++ b/include/v/vere.h @@ -788,15 +788,15 @@ /** Main loop, new style. **/ - /* u2_lo_boot(): restore or create pier. - */ - void - u2_lo_boot(void); - /* u2_lo_loop(): enter main event loop. */ void - u2_lo_loop(u2_reck* rec_u); + u2_lo_loop(void); + + /* u2_lo_lead(): actions on promotion to leader. + */ + void + u2_lo_lead(u2_reck* rec_u); /* u2_lo_exit(): shut down io across pier. */ @@ -1083,10 +1083,10 @@ u2_bean u2_raft_readopt(u2_ropt* rop_u, const c3_c* arg_c); - /* u2_raft_io_init(): initialize raft I/O. + /* u2_raft_init(): start Raft process. */ void - u2_raft_io_init(void); + u2_raft_init(void); /* u2_raft_work(): poke, kick, and push pending events. */ diff --git a/v/loop.c b/v/loop.c index c6a588d80..1549fe4ed 100644 --- a/v/loop.c +++ b/v/loop.c @@ -164,7 +164,6 @@ _lo_init() u2_term_io_init(); u2_http_io_init(); u2_save_io_init(); - u2_raft_io_init(); u2_batz_io_init(); } @@ -630,10 +629,10 @@ _lo_slow() #endif } -/* u2_lo_boot(): restore or create pier. +/* u2_lo_boot(): begin main event loop. */ void -u2_lo_boot() +u2_lo_loop() { uv_loop_t* lup_u = uv_default_loop(); @@ -643,13 +642,17 @@ u2_lo_boot() // signal(SIGIO, SIG_IGN); // linux is wont to produce for some reason _lo_init(); - u2_sist_boot(); + u2_raft_init(); + + if ( u2_no == u2_Host.ops_u.bat ) { + uv_run(u2L, UV_RUN_DEFAULT); + } } -/* u2_lo_loop(): begin main event loop. +/* u2_lo_lead(): actions on promotion to leader. */ void -u2_lo_loop(u2_reck* rec_u) +u2_lo_lead(u2_reck* rec_u) { _lo_talk(); { diff --git a/v/main.c b/v/main.c index ec50a5ed5..fccd48799 100644 --- a/v/main.c +++ b/v/main.c @@ -410,10 +410,7 @@ main(c3_i argc, u2_lo_grab("main", u2_none); - u2_lo_boot(); + u2_lo_loop(); - if ( u2_no == u2_Host.ops_u.bat ) { - u2_lo_loop(u2_Host.arv_u); - } return 0; } diff --git a/v/raft.c b/v/raft.c index 7a3e5b80e..d606bfb10 100644 --- a/v/raft.c +++ b/v/raft.c @@ -85,6 +85,19 @@ _raft_election_rand() return ((float) rand() / RAND_MAX) * 150; } +/* _raft_promote(): actions on raft leader election. +*/ +static void +_raft_promote(u2_raft* raf_u) +{ + raf_u->typ_e = u2_raty_lead; + + u2_sist_boot(); + if ( u2_no == u2_Host.ops_u.bat ) { + u2_lo_lead(u2A); + } +} + /* _raft_do_rest(): act on an incoming raft RPC request. */ static void @@ -545,13 +558,13 @@ _raft_lone_init(u2_raft* raf_u) { uL(fprintf(uH, "raft: single-instance mode\n")); - raf_u->typ_e = u2_raty_lead; + _raft_promote(raf_u); } -/* u2_raft_io_init(): begin raft I/O. +/* u2_raft_init(): start Raft process. */ void -u2_raft_io_init() +u2_raft_init() { u2_raft* raf_u = u2R; @@ -782,7 +795,6 @@ void u2_raft_work(u2_reck* rec_u) { if ( u2R->typ_e != u2_raty_lead ) { - uL(fprintf(uH, "raft: working while not leader?!\n")); c3_assert(rec_u->ova.egg_u == 0); if ( u2_nul != rec_u->roe ) { uL(fprintf(uH, "raft: dropping roe!!\n")); diff --git a/v/sist.c b/v/sist.c index 8503f1249..291e673e4 100644 --- a/v/sist.c +++ b/v/sist.c @@ -863,5 +863,4 @@ u2_sist_boot(void) { u2_http_ef_bake(); } - }