package granary
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=8b18780ea373be48301d9f333925860a2f9110fc0ac28684295118d72b65a67e
sha512=25ca3c9c5e2b528704a542502e0f37dc33ba003f65622d969b8c2b800778585f8ef0cf89b36e6679832e3993e8303aecddfc662742baf7044d6afe4a796b8f11
doc/granary.store/Granary_store/History/index.html
Module Granary_store.HistorySource
Append-only commit-log records for whole-DB as-of time travel (#266).
Each committed root is recorded as a fixed-width 28-byte record: txn_id(8) ++ timestamp(8) ++ root_page(8) ++ crc32(4), big-endian, with the CRC32 (IEEE polynomial) computed over the first 24 bytes. A torn or corrupt tail record is dropped on load — the database header remains the source of truth for the live head.
type record = {txn_id : int64;(*monotonic commit id
*)timestamp : int64;(*wall-clock ms since epoch at commit
*)root_page : int64;(*meta-tree root committed at
*)txn_id
}One committed whole-DB snapshot.
A target to resolve against the log.
type sink = {append : record -> unit Lwt.t;(*append one record; best-effort
*)load : unit -> record list Lwt.t;(*all records in ascending txn order
*)
}An injected append-only log backend (file, block device, or in-memory).
Fixed serialized size of one record, in bytes.
Serialize a record to a fresh record_size-byte buffer.
Decode a single record_size-byte record. None if the buffer is too short or the CRC does not match.
Parse a buffer of concatenated records. Stops at the first short or CRC-failing record (a torn tail), returning every valid record before it.
resolve records target returns the record with the largest key <= the target — txn_id for `Txn, timestamp for `Ts — or None if every record is newer (or the list is empty). The maximum is computed over the matching keys, so a non-monotonic `Ts log resolves correctly; equal-key ties resolve to the later record in list order (the later txn). `Ts is only meaningful under a monotonic commit clock.