diff options
| author | eunhhu <[email protected]> | 2026-09-25 16:06:21 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-25 16:06:21 +0100 |
| commit | 517d5cf263bdbea232186636ce99e7c3be15d00f (patch) | |
| tree | fe39aee427379bf75b91e70422039587086ea931 /prototypes/connections/pure-run.c | |
| parent | 18675f3e45fa0896efd777bf66ad0ec4c8157d36 (diff) | |
| download | pure-517d5cf263bdbea232186636ce99e7c3be15d00f.tar.gz pure-517d5cf263bdbea232186636ce99e7c3be15d00f.zip | |
Save app changes in bursts
A save now publishes everything since the last save in one commit: the
documents messages edited and the states that changed. If it fails, every
event since the last save is undone (values, text and list drafts, the
list undo log, event and tick counts), so an event reported as successful
is stored and a failed one leaves no trace.
By default each key, text and message event saves before it returns, as
before. With pure_app_defer events apply at once and a host saves a burst
with one commit; a key's document joins a burst once, so revisions move
one per save. On the Pi's SD card 600 events take 6.3 s saved one by one,
0.97 s in bursts of 8 and 0.34 s in bursts of 64. pure-run takes --batch N.
Tests compare a deferred stored app that saves at random and sometimes
stops unsaved with an app that replays only the saved events, undo a whole
burst on a failed save, and kill a process while it saves a burst.
Diffstat (limited to 'prototypes/connections/pure-run.c')
| -rw-r--r-- | prototypes/connections/pure-run.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/prototypes/connections/pure-run.c b/prototypes/connections/pure-run.c index 7b6e253..6e4a6e1 100644 --- a/prototypes/connections/pure-run.c +++ b/prototypes/connections/pure-run.c @@ -8,7 +8,8 @@ /* Test host for a verified module: reads commands from stdin and prints one * JSON snapshot per command. Not a product interface. With --store the app's * states live in that tree store: it starts from them, and frame changes are - * saved at the end of input or by save. + * saved at the end of input or by save. --batch N defers saving and saves + * every N commands (and at the end), so N events share one commit. * down NAME | up NAME | frame [N] | type NAME HEX|- | replace PATH | save | show * Text states and text views print as JSON strings; cursors as byte positions; * lists as arrays of objects; indices as positions; a table view as an array @@ -134,9 +135,11 @@ static int hex(char c) { int main(int argc, char **argv) { static PureModule modules[2]; - bool stored = argc == 4 && !strcmp(argv[2], "--store"); - if ((argc != 2 && !stored) || !load(argv[1], &modules[0])) { - if (argc != 2 && !stored) fputs("pure-run MODULE [--store PATH] < commands\n", stderr); + bool stored = argc >= 4 && !strcmp(argv[2], "--store"); + long batch = argc == 6 && stored && !strcmp(argv[4], "--batch") ? strtol(argv[5], NULL, 10) : 0; + bool usage = argc != 2 && !(stored && argc == 4) && !(batch > 0 && batch <= 100000); + if (usage || !load(argv[1], &modules[0])) { + if (usage) fputs("pure-run MODULE [--store PATH [--batch N]] < commands\n", stderr); return 2; } if (stored && pure_store_init(argv[3]) != PURE_OK) { fprintf(stderr, "cannot open store %s\n", argv[3]); return 2; } @@ -144,6 +147,8 @@ int main(int argc, char **argv) { PureApp app; PureResult started = pure_app_start(&app, &modules[active], stored ? pure_tree_data(argv[3]) : (PureData){0}); if (started != PURE_OK) { fprintf(stderr, "cannot start (%d)\n", (int)started); return 2; } + if (batch && !pure_app_defer(&app, true)) { fputs("cannot defer saving\n", stderr); return 2; } + long unsaved = 0; static char line[1 << 16]; static unsigned char text[1 << 15]; int status = 0; @@ -176,6 +181,10 @@ int main(int argc, char **argv) { } else if (!strcmp(command, "save")) { if (pure_app_save(&app) != PURE_OK) failure = "save failed"; } else if (strcmp(command, "show")) failure = "unknown command"; + if (batch && strcmp(command, "show") && ++unsaved == batch) { + unsaved = 0; + if (pure_app_save(&app) != PURE_OK) failure = "save failed"; + } if (failure) status = 1; show(&app, failure); } |
