aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes/connections/state.h
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-25 11:40:05 +0100
committereunhhu <[email protected]>2026-09-25 11:40:05 +0100
commit12410be7ec2a030e8c3adcf318d87d5ac2954e1d (patch)
tree76c9b7e55fb73e00242e287ffb7de8ebd92bf78b /prototypes/connections/state.h
parentaf3d6d38a1494607507f63ab6f2e120ea21bb315 (diff)
downloadpure-12410be7ec2a030e8c3adcf318d87d5ac2954e1d.tar.gz
pure-12410be7ec2a030e8c3adcf318d87d5ac2954e1d.zip
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.
Diffstat (limited to 'prototypes/connections/state.h')
-rw-r--r--prototypes/connections/state.h8
1 files changed, 8 insertions, 0 deletions
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);