aboutsummaryrefslogtreecommitdiffstats
path: root/core/log.h
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-28 10:43:45 +0100
committereunhhu <[email protected]>2026-09-28 10:43:45 +0100
commitcff25dd387376311b09bab3a58377fecbfe818e4 (patch)
tree13dcd7c742785f3f13d2466e02e10012479d0418 /core/log.h
parent923576863660d995476dffc7b285ee20e9707f27 (diff)
downloadpure-cff25dd387376311b09bab3a58377fecbfe818e4.tar.gz
pure-cff25dd387376311b09bab3a58377fecbfe818e4.zip
Log an app's saves in reused segments and write list images whole beside the store
Diffstat (limited to 'core/log.h')
-rw-r--r--core/log.h46
1 files changed, 46 insertions, 0 deletions
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 <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/* 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