1/* @ajax/mesh-jobd-store: the job log (jobd.rs `Store`): an append-only file of job log records
2 * (@ajax/mesh-jobs-log), rewritten whole -- the replica's own log -- when it grew past twice its last
3 * compact size plus 8 MiB. A write or sync that fails is fatal to the caller (fail-stop); a write that
4 * failed half-way is cut back to the last whole record first, so a torn tail is never followed by a
5 * record. At start the log is replayed (a torn last record dropped) and compacted. Without a path the
6 * table is kept in memory and nothing is written. */
7#ifndef MESH_JOBD_STORE_H
8#define MESH_JOBD_STORE_H
910#include "mesh/jobs/log.h"
11#include "mesh/jobs/out.h"
1213#include <stdbool.h>
14#include <stddef.h>
15#include <stdint.h>
1617typedef struct mjd_store mjd_store;
18typedef void (*mjd_log_fn)(void *ctx, const char *line);
1920/* Opens (creates) the log at path (NULL: in memory), replays it into *rep and rewrites it compacted.
21 * Info lines (a torn tail dropped, records replayed) go to log (may be NULL). NULL with *err. */
22mjd_store *mjd_store_open(const char *path, mj_replica *rep, mjd_log_fn log, void *ctx, char **err);
23void mjd_store_free(mjd_store *s);
24bool mjd_store_persisted(const mjd_store *s);
25/* Rewrites the log as r's own (a compaction): through a renamed file, so a failure leaves it as it was. */
26bool mjd_store_rewrite(mjd_store *s, const mj_replica *r, char **err);
27/* The log grew past twice its last compact size plus 8 MiB. */
28bool mjd_store_wants_compact(const mjd_store *s);
29/* The node's disk (mj_durable): appends records, fsyncs on demand. */
30mj_disk mjd_store_disk(mjd_store *s);
31/* Tests: the next append writes only its first k bytes and fails (a torn write). */
32void mjd_store_tear_next(mjd_store *s, size_t k);
3334#endif