package plebeia

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

Module Plebeia.Commit_treeSource

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.

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

    The index in the context for Commit.t

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

Create a new empty commit tree file

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

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

Sourceval open_for_write : ?resize_step_bytes:int -> key:Storage.writer_key -> string -> t Lwt.t
Sourceval 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.

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

Write the modifications to t to the disk.

Sourceval commit : t -> unit Lwt.t
Sourceval flush : t -> unit Lwt.t
Sourceval 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.

Sourceval may_forget : t -> t option

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

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

Close t.

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

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

If a binding already exists, it is overwritten.

Sourceval fold : (Commit_hash.t -> entry -> 'a -> 'a Lwt.t) -> t -> 'a -> 'a Lwt.t
Sourceval iter : (Commit_hash.t -> entry -> unit Lwt.t) -> t -> unit Lwt.t
Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourcemodule Internal : sig ... end

test and debugging purpose

OCaml

Innovation. Community. Security.