From 12410be7ec2a030e8c3adcf318d87d5ac2954e1d Mon Sep 17 00:00:00 2001 From: eunhhu Date: Fri, 25 Sep 2026 11:40:05 +0100 Subject: Keep draft versions readable within a transaction A module event may read a document and then edit it; the value it read must not change. pure_draft_version captures an immutable version and pure_draft_read_version lends its extents; pure_draft_hold suspends arena reclamation while a transaction still reads earlier versions. A test reads the original 200 KB after 400 held edits and checks reclamation on release. --- prototypes/connections/state.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'prototypes/connections/state.h') diff --git a/prototypes/connections/state.h b/prototypes/connections/state.h index d1bc0fa..d0b386c 100644 --- a/prototypes/connections/state.h +++ b/prototypes/connections/state.h @@ -24,6 +24,14 @@ int64_t pure_draft_revision(const PureDraft *); * splice, commit or close of this draft. */ PureResult pure_draft_read(const PureDraft *, size_t offset, size_t length, bool (*visit)(void *, PureSpan), void *context); +/* An immutable version of a draft's value. It stays readable while the draft + * is held (reclamation is suspended) and until the next commit or close. */ +typedef struct { uint64_t ref, bytes; } PureVersion; +PureVersion pure_draft_version(const PureDraft *); +PureResult pure_draft_read_version(const PureDraft *, PureVersion, size_t offset, size_t length, + bool (*visit)(void *, PureSpan), void *context); +/* While held, edits keep every earlier version's nodes (one transaction). */ +void pure_draft_hold(PureDraft *, bool held); /* Publish if the key is still at the draft's base revision. On success the * draft continues from the new revision; on any failure it is unchanged. */ PureResult pure_draft_commit(PureDraft *, int64_t *revision); -- cgit v1.2.3