From cff25dd387376311b09bab3a58377fecbfe818e4 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Mon, 28 Sep 2026 10:43:45 +0100 Subject: Log an app's saves in reused segments and write list images whole beside the store --- core/log.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ core/store.h | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 core/log.h (limited to 'core') diff --git a/core/log.h b/core/log.h new file mode 100644 index 0000000..44dbdfb --- /dev/null +++ b/core/log.h @@ -0,0 +1,46 @@ +#ifndef PURE_LOG_H +#define PURE_LOG_H +#include "flow.h" +#include "result.h" +#include +#include +#include + +/* An app's log beside its store (store/store-log.c): an entry a save, its + * number (one more than the entry before), whether the save also committed + * the tree, and its payload. An entry counts once pure_log_append returns + * PURE_OK: it is on the device. One thread uses a log. */ +typedef struct PureLog PureLog; +/* The log in directory (made empty when it has none). The entries found are + * checked (digests, numbers following on) up to the first that is not. */ +PureResult pure_log_open(const char *directory, PureLog **out); +void pure_log_close(PureLog *); +/* The last entry's number (0: none). */ +uint64_t pure_log_last(const PureLog *); +/* The entries from number from on (0: every entry kept), in order; payloads + * stay valid until the next append. STORE_ERROR when an entry from `from` on + * is missing; a visit that returns false stops. Only before appending. */ +PureResult pure_log_read(PureLog *, uint64_t from, + bool (*visit)(void *, uint64_t seq, bool tree, PureSpan payload), void *context); +/* Entries after seq no longer count: the next append follows seq, over them. */ +void pure_log_end(PureLog *, uint64_t seq); +/* Append the entry numbered seq (one more than the last) and make it durable: + * UNCERTAIN when writing or syncing failed (it may or may not be there). */ +PureResult pure_log_append(PureLog *, uint64_t seq, bool tree, PureSpan payload); +/* The last appended entry no longer counts (its save failed after it was + * written): the next append takes its number and its place. */ +void pure_log_retract(PureLog *); +/* Entries up to seq are no longer read: their segments may be used again. */ +void pure_log_release(PureLog *, uint64_t seq); +/* Bytes of the segments that hold entries not released. */ +uint64_t pure_log_bytes(const PureLog *); + +/* A list's image: a file of directory named after the list, replaced whole + * (written beside it, synced, renamed over it): pure_image_write writes the + * bytes of parts one after another, pure_image_read gives them back (malloc'd; + * NOT_FOUND when there is none, STORE_ERROR when damaged). The bytes of the + * image are digested: a file cut short or changed is refused. */ +PureResult pure_image_write(const char *directory, const char *name, const PureSpan *parts, size_t count); +PureResult pure_image_read(const char *directory, const char *name, unsigned char **bytes, size_t *size); +PureResult pure_image_remove(const char *directory, const char *name); +#endif diff --git a/core/store.h b/core/store.h index 64b8d9e..7086d3a 100644 --- a/core/store.h +++ b/core/store.h @@ -51,7 +51,7 @@ PureResult pure_store_keys(const char *path, bool (*visit)(void *, const char *k /* Fault hooks exist only in the separately built unit-test binary. */ typedef enum { PURE_AFTER_HEADER, PURE_BEFORE_FILE_SYNC, PURE_BEFORE_RENAME, PURE_BEFORE_DIR_SYNC, - PURE_COPY_RANGE_UNSUPPORTED_AFTER_PARTIAL + PURE_COPY_RANGE_UNSUPPORTED_AFTER_PARTIAL, PURE_LOG_BEFORE_WRITE, PURE_LOG_BEFORE_SYNC, PURE_IMAGE_BEFORE_RENAME } PureStoreStage; #ifdef PURE_STORE_TEST int pure_store_test_fault(PureStoreStage stage); -- cgit v1.2.3