Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boot: replay in subprocess #654

Merged
merged 14 commits into from
Jun 24, 2024
46 changes: 38 additions & 8 deletions pkg/vere/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "db/lmdb.h"
#include "getopt.h"
#include "libgen.h"
#include "spawn.h"

#include "ca_bundle.h"
#include "pace.h"
Expand Down Expand Up @@ -291,12 +292,13 @@ _main_getopt(c3_i argc, c3_c** argv)
{ "prop-url", required_argument, NULL, 2 },
{ "prop-name", required_argument, NULL, 3 },
//
{ "urth-loom", required_argument, NULL, 5 },
{ "no-demand", no_argument, NULL, 6 },
{ "swap", no_argument, NULL, 7 },
{ "swap-to", required_argument, NULL, 8 },
{ "toss", required_argument, NULL, 9 },
{ "urth-loom", required_argument, NULL, 5 },
{ "no-demand", no_argument, NULL, 6 },
{ "swap", no_argument, NULL, 7 },
{ "swap-to", required_argument, NULL, 8 },
{ "toss", required_argument, NULL, 9 },
{ "behn-allow-blocked", no_argument, NULL, 10 },
{ "serf-bin", required_argument, NULL, 11 },
//
{ NULL, 0, NULL, 0 },
};
Expand Down Expand Up @@ -340,6 +342,10 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.beb = c3y;
break;
}
case 11: { // serf-bin
u3_Host.wrk_c = strdup(optarg);
break;
}
// special args
//
case c3__loom: {
Expand Down Expand Up @@ -2315,6 +2321,28 @@ _cw_play_impl(c3_d eve_d, c3_d sap_d, c3_o mel_o, c3_o sof_o, c3_o ful_o)
return pay_d;
}

/* _cw_play_fork(): spawn a subprocess for event replay.
*/
static c3_i
_cw_play_fork()
{
pid_t pid;
c3_i sat_i;
c3_c *argv[] = { u3_Host.wrk_c, "play", u3_Host.dir_c }; // XX parameterize args
matthew-levan marked this conversation as resolved.
Show resolved Hide resolved

if ( 0 != posix_spawn(&pid, u3_Host.wrk_c, 0, 0, argv, 0) ) {
fprintf(stderr, "play: posix_spawn: %d\r\n", errno);
return 1;
}

if ( -1 == waitpid(pid, &sat_i, 0) ) {
fprintf(stderr, "play: waitpid: %d\r\n", errno);
return 1;
}

return WEXITSTATUS(sat_i);
}

/* _cw_play(): replay events, but better.
*/
static void
Expand Down Expand Up @@ -2966,8 +2994,6 @@ main(c3_i argc,

_main_self_path();

// XX add argument
//
if ( !u3_Host.wrk_c ) {
u3_Host.wrk_c = bin_c;
}
Expand Down Expand Up @@ -3110,7 +3136,11 @@ main(c3_i argc,
// we need the current snapshot's latest event number to
// validate whether we can execute disk migration
if ( u3_Host.ops_u.nuu == c3n ) {
_cw_play_impl(0, 0, c3n, c3n, c3n);
c3_i sat_i = _cw_play_fork();
if ( sat_i ) {
fprintf(stderr, "play: replay failed: %d\r\n", sat_i);
exit(sat_i);
}
// XX unmap loom, else parts of the snapshot could be left in memory
}

Expand Down
Loading