package granary

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

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.

Sourcetype record = {
  1. txn_id : int64;
    (*

    monotonic commit id

    *)
  2. timestamp : int64;
    (*

    wall-clock ms since epoch at commit

    *)
  3. root_page : int64;
    (*

    meta-tree root committed at txn_id

    *)
}

One committed whole-DB snapshot.

Sourcetype target = [
  1. | `Txn of int64
  2. | `Ts of int64
]

A target to resolve against the log.

Sourcetype sink = {
  1. append : record -> unit Lwt.t;
    (*

    append one record; best-effort

    *)
  2. load : unit -> record list Lwt.t;
    (*

    all records in ascending txn order

    *)
}

An injected append-only log backend (file, block device, or in-memory).

Sourceval record_size : int

Fixed serialized size of one record, in bytes.

Sourceval encode : record -> Cstruct.t

Serialize a record to a fresh record_size-byte buffer.

Sourceval decode : Cstruct.t -> record option

Decode a single record_size-byte record. None if the buffer is too short or the CRC does not match.

Sourceval decode_all : Cstruct.t -> record list

Parse a buffer of concatenated records. Stops at the first short or CRC-failing record (a torn tail), returning every valid record before it.

Sourceval resolve : record list -> target -> record option

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.