skip to content
==> include/mesh/fleet_plan.h <==
1/* @ajax/mesh-fleet-plan: the reconcile plan (fleet.rs plan) and a fresh fleet's first document
2 * (seed). */
3#ifndef MESH_FLEET_PLAN_H
4#define MESH_FLEET_PLAN_H
5
6#include "mesh/fleet_doc.h"
7
8#include <stdbool.h>
9#include <stdint.h>
10
11/* A program as it is on this member (the driver's inventory). */
12typedef struct {
13    char *name, *dir;
14    uint64_t hash;
15    bool has_prev;     /* the retained previous image's hash (rollback target) */
16    uint64_t prev;
17    bool run, failed, lockstep;
18} mfl_actual;
19
20mfl_actual mfl_actual_new(const char *name, const char *dir, uint64_t hash, bool has_prev, uint64_t prev, bool run);
21void mfl_actual_free(mfl_actual *a);
22
23typedef enum {
24    MFL_UNLOAD,
25    MFL_LOAD,     /* name, dir, hash, run */
26    MFL_UPGRADE,  /* name, dir, hash */
27    MFL_ROLLBACK,
28    MFL_RUN,      /* name, run */
29    MFL_RESET,
30    MFL_MIGRATE,  /* load it stopped, take its view from member `from` (which stops it), then run it */
31} mfl_kind;
32
33typedef struct {
34    mfl_kind kind;
35    char *name, *dir;
36    uint64_t hash;
37    bool run;
38    uint32_t from;
39} mfl_action;
40
41typedef struct {
42    mfl_action *v;
43    size_t n;
44} mfl_actions;
45
46bool mfl_action_eq(const mfl_action *a, const mfl_action *b);
47void mfl_actions_free(mfl_actions *a);
48
49/* skip(name, hash): programs this member does not run (no image for its executors) or already
50 * failed at this hash. resets: the reset generation applied per program (name -> decimal u32). */
51typedef bool (*mfl_skip_fn)(void *ctx, const char *name, uint64_t hash);
52
53/* What makes this member's programs match doc: unloads first (they free slots and heap), then loads,
54 * upgrades and rollbacks, then run states and resets. A failed program that should run is started
55 * again. resets maps a program to its applied generation (as text). */
56mfl_actions mfl_plan(const mfd_doc *doc, const mfl_actual *actual, size_t nactual, mfl_skip_fn skip, void *ctx, const char *const *reset_names,
57                     const uint32_t *reset_gens, size_t nresets, uint32_t me);
58
59/* The first document of a fresh fleet: the first leader's programs (each with its spec) and a group
60 * of every eligible up member for the lockstep program. backend_of(k) is member k's GPU backend kind
61 * (u32 max: unknown). */
62typedef uint32_t (*mfl_backend_fn)(void *ctx, uint32_t k);
63mfd_doc mfl_seed(char *const *names, const mfd_prog *specs, size_t n, const ml_list *up, mfl_backend_fn backend_of, void *ctx);
64
65#endif