From e4bc782d09fe1c80098a38380b3959863dfe188f Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sat, 26 Sep 2026 05:39:47 +0100 Subject: Add a store handle that shares one mapping Opening a draft by path opened the directory and the file, mapped the whole file, read the head, and undid all of it on close: nine system calls for every GET. pure_store_open keeps the store open for one owner thread; drafts opened through it share a reference-counted mapping of the newest version, and opening one only checks whether the file changed (its identity and its head: two system calls). A commit of its drafts maps the new version once and moves them all onto it. A compaction by another writer is noticed and followed, while drafts of the old file keep reading it and relocate their extents when they commit. pure_store_data gives modules the same through a handle. --- prototypes/connections/state.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'prototypes/connections/state.h') diff --git a/prototypes/connections/state.h b/prototypes/connections/state.h index 55ad257..25c0f61 100644 --- a/prototypes/connections/state.h +++ b/prototypes/connections/state.h @@ -21,6 +21,15 @@ PureResult pure_draft_open(const char *path, const char *key, PureDraft **out); * under a name that is never a document key (hosts listing documents do not * see it). name is a valid key of at most 63 bytes. */ PureResult pure_state_open(const char *path, const char *name, PureDraft **out); +/* A store kept open by one owner thread. Drafts opened through it share one + * mapping of the newest version, and opening one checks only whether the file + * changed; commits of its drafts map the new version once. It must outlive + * its drafts. */ +typedef struct PureStore PureStore; +PureResult pure_store_open(const char *path, PureStore **out); +void pure_store_close(PureStore *); +PureResult pure_store_draft(PureStore *, const char *key, PureDraft **out); +PureResult pure_store_state(PureStore *, const char *name, PureDraft **out); /* Memory only. Fails without change on a bad range or when memory runs out. */ PureResult pure_draft_splice(PureDraft *, size_t offset, size_t remove, PureSpan insert); size_t pure_draft_size(const PureDraft *); -- cgit v1.2.3