aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes/connections/state.h
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-26 06:34:39 +0100
committereunhhu <[email protected]>2026-09-26 06:34:39 +0100
commite7a2d8a6715ab48f887acfe1d14e32099e0ed7ff (patch)
treed57e26614f5ffd4a996955ff24e4dc735f6bd510 /prototypes/connections/state.h
parent9408c57e0f2485fd7960135c931aa120dcb3fa8f (diff)
downloadpure-e7a2d8a6715ab48f887acfe1d14e32099e0ed7ff.tar.gz
pure-e7a2d8a6715ab48f887acfe1d14e32099e0ed7ff.zip
Lend stored extents to reads instead of copying them
A read of a stored document now answers with the store mapping's extents through writev, without copying the document. pure_draft_mapping takes a reference to the mapping a draft opened through a handle reads from; the answer keeps it until the last byte is sent, so the version read goes out intact even if the document changes or a compaction replaces the file meanwhile. Replies the mapping does not hold are copied as before. pure-serve's output is now a list of extents (the head first). One thread serves 2,761 1 MiB reads per second (axum: 1,380) and 128k small ones.
Diffstat (limited to 'prototypes/connections/state.h')
-rw-r--r--prototypes/connections/state.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/prototypes/connections/state.h b/prototypes/connections/state.h
index 55474c0..0945475 100644
--- a/prototypes/connections/state.h
+++ b/prototypes/connections/state.h
@@ -30,6 +30,16 @@ 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);
+/* Stored extents can outlive their draft: pure_draft_mapping takes a
+ * reference to the mapping a draft opened through a handle reads its stored
+ * nodes from (NULL for other drafts). Spans that mapping holds stay readable
+ * until the reference is released, after the draft closes and after the
+ * store moves on. Spans of a draft's unsaved edits are not in it. Use it on
+ * the handle's owner thread. */
+typedef struct PureMapping PureMapping;
+PureMapping *pure_draft_mapping(const PureDraft *);
+bool pure_mapping_holds(const PureMapping *, PureSpan);
+void pure_mapping_release(PureMapping *);
/* Pinned, drafts open at the version found when pinning, without checking
* the file each time (a host pins for one burst of requests); commits made
* through the handle still move it on. */