package plebeia

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

Tree shaped append-only persistent storage for commit entries.

The commit information is also recorded to the Plebeia context file as a linked list, but it is not random-accessible and very slow.

Commit_tree provides a fast random access from the commit hash to its Commit.t index in the context and the parent commit hash.

XXX Bug: currently the tree never free entries on memory. This may cause unexpected memory usage. 57.65 MiB for 160,000 commits.

type entry = {
  1. parent : Commit_hash.t option;
  2. index : Index.t;
    (*

    The index in the context for Commit.t

    *)
}
type t
val create : ?length:Index.t -> ?resize_step_bytes:int -> key:Storage.writer_key -> string -> t Lwt.t

Create a new empty commit tree file

val open_existing_for_read : string -> (t, Error.t) result Lwt.t

If the file exists, load its latest commit tree. Otherwise, returns None

val open_for_write : ?resize_step_bytes:int -> key:Storage.writer_key -> string -> t Lwt.t
val offline_gc : ?resize_step_bytes:int -> string -> (unit, Error.t) result Lwt.t

gc fn replaces the commit tree file fn by a new one only with the latest commit found in fn.

The original file is backed up as fn ^ ".old". If the backup file already exists, it is overwritten.

This GC is offline. Never call this function when fn is being used.

val write : t -> (unit, Error.t) result

Write the modifications to t to the disk.

val commit : t -> unit Lwt.t
val flush : t -> unit Lwt.t
val update_reader : t -> t Lwt.t

Update t to the latest commit tree on the disk.

The reader process of the commit tree must call this function time to time to get the updates by the writer.

val may_forget : t -> t option

Forget the on-memory cache of t. This fails and returns None if t has unsaved updates.

val close : t -> (unit, Error.t) result Lwt.t

Close t.

In Writer mode, it saves before closing. Save errors do not prevent the closing.

val mode : t -> Storage.mode
val mem : t -> Commit_hash.t -> bool
val find : t -> Commit_hash.t -> entry option
val add : t -> Commit_hash.t -> entry -> t

If a binding already exists, it is overwritten.

val fold : (Commit_hash.t -> entry -> 'a -> 'a Lwt.t) -> t -> 'a -> 'a Lwt.t
val iter : (Commit_hash.t -> entry -> unit Lwt.t) -> t -> unit Lwt.t
val children : t -> (Commit_hash.t -> (Commit_hash.t * entry) list) Lwt.t

children t returns a function to query children of the given hash.

Note that children t takes some time since it traverses the whole commit tree.

val geneses : t -> (Commit_hash.t * entry) list Lwt.t

Get the genesis commit hashes and the entries, which have no parent.

This function traverses the whole commit tree, therefore inefficient.

val ordered_fold : (Commit_hash.t -> entry -> children:(Commit_hash.t * entry) list -> 'a -> 'a Lwt.t) -> t -> 'a -> 'a Lwt.t

Folding. Parent commits are folded earlier than their children

Note that ordered_fold takes some time since it traverse the whole commit tree.

module Internal : sig ... end

test and debugging purpose