skip to content
==> include/mesh/jobs/out.h <==
1/* @ajax/mesh-jobs-out: what the job node asks of the world (jobs.rs `Out`), and `durable`: the
2 * node's outputs made durable in order. Every PERSIST is appended to the log, and the log is synced
3 * before the first SEND or ANSWER after it. The first append or sync that fails stops everything:
4 * the outputs before it are returned with the error, and nothing after it is ever sent (fail-stop,
5 * review finding 4). */
6#ifndef MESH_JOBS_OUT_H
7#define MESH_JOBS_OUT_H
8
9#include "mesh/jobs/frame.h"
10#include "mesh/jobs/id.h"
11#include "mesh/jobs/log.h"
12
13#include <stdbool.h>
14#include <stddef.h>
15#include <stdint.h>
16
17typedef enum {
18    MJ_OUT_SEND,       /* to, frame */
19    MJ_OUT_PUSH_BLOB,  /* blobd: push job's blob `hash` (in this member's store or memory) to member `to` */
20    MJ_OUT_FETCH_BLOB, /* blobd: fetch blob `hash` from the holders (else any member), keep it durably */
21    MJ_OUT_BLOB_DONE,  /* blobd: job's blob `hash` needs no more pushes from here: its bytes may leave memory */
22    MJ_OUT_PERSIST,    /* append `log` to the log and sync, before the sends that follow it */
23    MJ_OUT_RUN,        /* the local driver: run lease `run` */
24    MJ_OUT_CUT,        /* the local driver: drop lease `lease`'s items from `cut` on (0: all) */
25    MJ_OUT_ANSWER,     /* a change's answer (after its commit), by the caller's token: ok, text */
26    MJ_OUT_LOG,        /* a log line: text */
27} mj_out_kind;
28
29typedef struct {
30    mj_out_kind kind;
31    uint32_t to;
32    mj_frame frame;
33    mj_job_id job;
34    mj_hash hash;
35    uint32_t holders;
36    mj_log log;
37    mj_lease_msg run;
38    uint64_t lease, cut;
39    uint64_t token;
40    bool ok;
41    char *text;
42} mj_out;
43
44typedef struct {
45    mj_out *v;
46    size_t n, cap;
47} mj_outs;
48
49void mj_out_free(mj_out *o);
50void mj_outs_push(mj_outs *v, mj_out o); /* takes o */
51void mj_outs_append(mj_outs *dst, mj_outs *src); /* moves src's outputs (src is empty after) */
52void mj_outs_free(mj_outs *v);
53
54/* Constructors (they take what they're given). */
55mj_out mj_out_send(uint32_t to, mj_frame f);
56mj_out mj_out_push_blob(uint32_t to, mj_job_id job, mj_hash hash);
57mj_out mj_out_fetch_blob(mj_job_id job, mj_hash hash, uint32_t holders);
58mj_out mj_out_blob_done(mj_job_id job, mj_hash hash);
59mj_out mj_out_persist(mj_log l);
60mj_out mj_out_run(mj_lease_msg l);
61mj_out mj_out_cut(uint64_t lease, uint64_t cut);
62mj_out mj_out_answer(uint64_t token, bool ok, char *text);
63mj_out mj_out_log(char *text);
64
65/* Where the node's log goes (jobd's store; a test's faulty disk). Each returns false with *err (the
66 * caller frees it) on failure. */
67typedef struct {
68    void *ctx;
69    bool (*append)(void *ctx, const mj_log *l, char **err);
70    bool (*sync)(void *ctx, char **err);
71} mj_disk;
72
73/* Takes `outs`: returns, in order, the outputs to act on (every PERSIST written and dropped). On a
74 * failure *ok is false and *err says why; what follows the failure is dropped. */
75mj_outs mj_durable(mj_outs *outs, const mj_disk *disk, bool *ok, char **err);
76
77#endif