serf: disables auto |pack, refactors loading from rock (-r)

This commit is contained in:
Joe Bryan 2020-06-11 16:01:19 -07:00
parent f48dd41ca8
commit 19da74d146
6 changed files with 83 additions and 97 deletions

View File

@ -12,7 +12,7 @@
c3_d dun_d; // last event processed c3_d dun_d; // last event processed
c3_l mug_l; // hash of state c3_l mug_l; // hash of state
c3_o pac_o; // pack kernel c3_o pac_o; // pack kernel
c3_o rec_o; // reclaim cash c3_o rec_o; // reclaim cache
c3_o mut_o; // mutated kerne c3_o mut_o; // mutated kerne
u3_noun sac; // space measurementl u3_noun sac; // space measurementl
} u3_serf; } u3_serf;
@ -24,6 +24,11 @@
u3_noun u3_noun
u3_serf_init(u3_serf* sef_u); u3_serf_init(u3_serf* sef_u);
/* u3_serf_unpack(): initialize from rock at [eve_d].
*/
void
u3_serf_unpack(u3_serf* sef_u, c3_d eve_d);
/* u3_serf_writ(): apply writ [wit], producing plea [*pel] on c3y. /* u3_serf_writ(): apply writ [wit], producing plea [*pel] on c3y.
*/ */
c3_o c3_o

View File

@ -1133,6 +1133,11 @@
c3_o c3_o
u3_pier_save(u3_pier* pir_u); u3_pier_save(u3_pier* pir_u);
/* u3_pier_pack(): save a portable snapshot.
*/
c3_o
u3_pier_pack(u3_pier* pir_u);
/* u3_pier_stub(): get the One Pier for unreconstructed code. /* u3_pier_stub(): get the One Pier for unreconstructed code.
*/ */
u3_pier* u3_pier*

View File

@ -574,9 +574,6 @@ _pier_play_read(u3_play* pay_u)
} }
} }
c3_o
u3_pier_pack(u3_pier* pir_u);
/* _pier_play(): send a batch of events to the worker for log replay. /* _pier_play(): send a batch of events to the worker for log replay.
*/ */
static void static void

View File

@ -1401,6 +1401,9 @@ _term_io_kick(u3_auto* car_u, u3_noun wir, u3_noun cad)
// //
case c3__pack: { case c3__pack: {
ret_o = c3y; ret_o = c3y;
// XX would be
//
// u3_assure(u3_pier_pack(car_u->pir_u));
} break; } break;
} }
} }

View File

@ -175,54 +175,7 @@ main(c3_i argc, c3_c* argv[])
u3V.sen_d = u3V.dun_d = u3m_boot(dir_c); u3V.sen_d = u3V.dun_d = u3m_boot(dir_c);
if ( eve_d ) { if ( eve_d ) {
c3_o roc_o; u3_serf_unpack(&u3V, eve_d);
c3_c nam_c[8193];
snprintf(nam_c, 8192, "%s/.urb/roc/%" PRIu64 ".jam", u3V.dir_c, eve_d);
struct stat buf_b;
c3_i fid_i = open(nam_c, O_RDONLY, 0644);
if ( (fid_i < 0) || (fstat(fid_i, &buf_b) < 0) ) {
fprintf(stderr, "serf: rock: %s not found\r\n", nam_c);
roc_o = c3n;
}
else {
fprintf(stderr, "serf: rock: %s found\r\n", nam_c);
roc_o = c3y;
}
close(fid_i);
if ( c3y == roc_o ) {
if ( c3n == u3e_hold() ) {
fprintf(stderr, "serf: unable to backup checkpoint\r\n");
}
else {
u3m_wipe();
if ( c3n == u3m_rock_load(u3V.dir_c, eve_d) ) {
fprintf(stderr, "serf: compaction failed, restoring checkpoint\r\n");
if ( c3n == u3e_fall() ) {
fprintf(stderr, "serf: unable to restore checkpoint\r\n");
c3_assert(0);
}
}
if ( c3n == u3e_drop() ) {
fprintf(stderr, "serf: warning: orphaned backup checkpoint file\r\n");
}
fprintf(stderr, "serf (%" PRIu64 "): compacted loom\r\n", eve_d);
u3V.sen_d = u3V.dun_d = eve_d;
// save now for flexibility
//
u3e_save();
}
}
} }
} }

View File

@ -290,9 +290,7 @@ _serf_static_grab(void)
static void static void
_serf_pack(u3_serf* sef_u) _serf_pack(u3_serf* sef_u)
{ {
// skip for now _serf_static_grab();
//
// _serf_static_grab();
u3l_log("serf (%" PRIu64 "): compacting loom\r\n", sef_u->dun_d); u3l_log("serf (%" PRIu64 "): compacting loom\r\n", sef_u->dun_d);
@ -301,39 +299,11 @@ _serf_pack(u3_serf* sef_u)
return; return;
} }
if ( c3n == u3e_hold() ) { u3_serf_unpack(sef_u, sef_u->dun_d);
u3l_log("serf: unable to backup checkpoint\r\n");
return;
}
u3m_wipe();
if ( c3n == u3m_rock_load(sef_u->dir_c, sef_u->dun_d) ) {
u3l_log("serf: compaction failed, restoring checkpoint\r\n");
if ( c3n == u3e_fall() ) {
fprintf(stderr, "serf: unable to restore checkpoint\r\n");
c3_assert(0);
}
}
if ( c3n == u3e_drop() ) {
u3l_log("serf: warning: orphaned backup checkpoint file\r\n");
}
// leave these for now
//
// if ( c3n == u3m_rock_drop(sef_u->dir_c, sef_u->dun_d) ) {
// u3l_log("serf: warning: orphaned state file\r\n");
// }
u3l_log("serf (%" PRIu64 "): compacted loom\r\n", sef_u->dun_d); u3l_log("serf (%" PRIu64 "): compacted loom\r\n", sef_u->dun_d);
_serf_static_grab(); _serf_static_grab();
// save now for flexibility
//
u3e_save();
} }
/* u3_serf_post(): update serf state post-writ. /* u3_serf_post(): update serf state post-writ.
@ -346,7 +316,7 @@ u3_serf_post(u3_serf* sef_u)
sef_u->rec_o = c3n; sef_u->rec_o = c3n;
} }
// XX this runs on replay too // XX this runs on replay too, |mass s/b elsewhere
// //
if ( c3y == sef_u->mut_o ) { if ( c3y == sef_u->mut_o ) {
sef_u->mut_o = c3n; sef_u->mut_o = c3n;
@ -432,14 +402,11 @@ _serf_sure_feck(u3_serf* sef_u, c3_w pre_w, u3_noun vir)
if ( (pre_w > low_w) && !(pos_w > low_w) ) { if ( (pre_w > low_w) && !(pos_w > low_w) ) {
// XX set flag(s) in u3V so we don't repeat endlessly? // XX set flag(s) in u3V so we don't repeat endlessly?
// XX pack here too?
// //
pac_o = c3y;
rec_o = c3y; rec_o = c3y;
pri = 1; pri = 1;
} }
else if ( (pre_w > hig_w) && !(pos_w > hig_w) ) { else if ( (pre_w > hig_w) && !(pos_w > hig_w) ) {
pac_o = c3y;
rec_o = c3y; rec_o = c3y;
pri = 0; pri = 0;
} }
@ -453,12 +420,6 @@ _serf_sure_feck(u3_serf* sef_u, c3_w pre_w, u3_noun vir)
rec_o = c3y; rec_o = c3y;
} }
// pack every 20K events
//
if ( 0 == (sef_u->dun_d % 20000ULL) ) {
pac_o = c3y;
}
// notify daemon of memory pressure via "fake" effect // notify daemon of memory pressure via "fake" effect
// //
if ( u3_none != pri ) { if ( u3_none != pri ) {
@ -782,7 +743,7 @@ _serf_play_list(u3_serf* sef_u, u3_noun eve)
_serf_sure_core(sef_u, u3k(cor)); _serf_sure_core(sef_u, u3k(cor));
// process effects to set pack/reclaim flags // process effects to set u3_serf_post flags
// //
u3z(_serf_sure_feck(sef_u, pre_w, u3k(vir))); u3z(_serf_sure_feck(sef_u, pre_w, u3k(vir)));
@ -806,8 +767,7 @@ _serf_play_list(u3_serf* sef_u, u3_noun eve)
u3z(gon); u3z(gon);
// XX reclaim/pack on meme // XX reclaim on meme ?
// XX retry?
// //
// send failure notification // send failure notification
@ -964,6 +924,8 @@ u3_serf_live(u3_serf* sef_u, u3_noun com, u3_noun* ret)
return c3y; return c3y;
} }
// NB: the %pack $writ only saves the rock, it doesn't load it
//
case c3__pack: { case c3__pack: {
c3_d eve_d; c3_d eve_d;
@ -1099,6 +1061,67 @@ _serf_ripe(u3_serf* sef_u)
return u3nc(u3i_chubs(1, &sef_u->dun_d), sef_u->mug_l); return u3nc(u3i_chubs(1, &sef_u->dun_d), sef_u->mug_l);
} }
/* u3_serf_unpack(): initialize from rock at [eve_d].
*/
void
u3_serf_unpack(u3_serf* sef_u, c3_d eve_d)
{
c3_o roc_o;
c3_c nam_c[8193];
snprintf(nam_c, 8192, "%s/.urb/roc/%" PRIu64 ".jam", sef_u->dir_c, eve_d);
struct stat buf_b;
c3_i fid_i = open(nam_c, O_RDONLY, 0644);
if ( (fid_i < 0) || (fstat(fid_i, &buf_b) < 0) ) {
fprintf(stderr, "serf: rock: %s not found\r\n", nam_c);
roc_o = c3n;
}
else {
fprintf(stderr, "serf: rock: %s found\r\n", nam_c);
roc_o = c3y;
}
close(fid_i);
if ( c3y == roc_o ) {
if ( c3n == u3e_hold() ) {
fprintf(stderr, "serf: unable to backup checkpoint\r\n");
}
else {
u3m_wipe();
if ( c3n == u3m_rock_load(sef_u->dir_c, eve_d) ) {
fprintf(stderr, "serf: compaction failed, restoring checkpoint\r\n");
if ( c3n == u3e_fall() ) {
fprintf(stderr, "serf: unable to restore checkpoint\r\n");
c3_assert(0);
}
}
if ( c3n == u3e_drop() ) {
fprintf(stderr, "serf: warning: orphaned backup checkpoint file\r\n");
}
// leave rocks on disk
//
// if ( c3n == u3m_rock_drop(sef_u->dir_c, sef_u->dun_d) ) {
// u3l_log("serf: warning: orphaned state file\r\n");
// }
fprintf(stderr, "serf (%" PRIu64 "): compacted loom\r\n", eve_d);
sef_u->sen_d = sef_u->dun_d = eve_d;
// save now for flexibility
//
u3e_save();
}
}
}
/* u3_serf_init(): init or restore, producing status. /* u3_serf_init(): init or restore, producing status.
*/ */
u3_noun u3_noun