From e7a2d8a6715ab48f887acfe1d14e32099e0ed7ff Mon Sep 17 00:00:00 2001 From: eunhhu Date: Sat, 26 Sep 2026 06:34:39 +0100 Subject: 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. --- prototypes/connections/state.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'prototypes/connections/state.h') 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. */ -- cgit v1.2.3