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/module-store.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'prototypes/connections/module-store.c') diff --git a/prototypes/connections/module-store.c b/prototypes/connections/module-store.c index 02d6361..7e759fd 100644 --- a/prototypes/connections/module-store.c +++ b/prototypes/connections/module-store.c @@ -58,6 +58,29 @@ static PureResult save(void *context, void *const *documents, size_t document_co return result; } +/* Through a store handle: documents and states share its mapping. */ +static PureResult open_handle_document(void *context, uint32_t collection, const char *key, void **document, + int64_t *revision) { + (void)collection; + PureDraft *draft; + PureResult result = pure_store_draft(context, key, &draft); + if (result != PURE_OK) return result; + pure_draft_hold(draft, true); + *document = draft; + *revision = pure_draft_revision(draft); + return PURE_OK; +} + +static PureResult handle_state(void *context, const char *name, PureDraft **out) { + return pure_store_state(context, name, out); +} + +PureData pure_store_data(PureStore *store) { + return (PureData){.context = store, .open = open_handle_document, .version = version, .read = read, + .splice = splice, .commit = commit, .close = close_document, .state = handle_state, + .save = save}; +} + PureData pure_tree_data(const char *path) { return (PureData){.context = (void *)path, .open = open_document, .version = version, .read = read, .splice = splice, .commit = commit, .close = close_document, -- cgit v1.2.3