Module type Ezirmin.Log

module type Log = sig .. end


An efficient write-optimized append-only logs



Log provides mergeable append-only logs with support for paginated reads. Appending messages to logs and merging two logs are constant time operations. Logs can be read in reverse chronological order. Logs also provide support for paginated reads.
include Ezirmin.Repo
type elt 
The type of value stored in the log.
type cursor 
The type of cursor. The cursor is an abstraction that represents a specifc position in the log.
val append : ?message:string ->
branch -> path:string list -> elt -> unit Lwt.t
append m b p c appends the message m to the log at path b in the branch b with commit message c. Append is an O(1) operation.
val get_cursor : branch -> path:string list -> cursor option Lwt.t
get_cursor b p fetches the cursor that points to the latest message in in the log at path p in the branch b. If the log at path p is empty, then the operation returns None.
val read : cursor ->
num_items:int -> (elt list * cursor option) Lwt.t
read c n reads the next n messages in reverse chronological order at the cursor. The operation returns the list of messages read and an optional cursor value that represents the tail of the last message read. The cursor can then be used to read subsequent messages.

If the number of requested message is greater than the number of available messages in the log, then the operation returns the available messages and None for the cursor.

val read_all : branch -> path:string list -> elt list Lwt.t
read_all b p reads all the messages in the log at path p in the branch b in reverse chronological order.
val at_time : cursor -> Ptime.t option
at_time c returns the timestamp of the latest message in the cursor c.
val is_earlier : cursor -> than:cursor -> bool option
is_earlier x y returns true if the latest message in x is older than the latest message in y.
val is_later : cursor -> than:cursor -> bool option
is_later x y returns true if the latest message in x is newer than the latest message in y.

Watch


val watch : branch ->
path:string list ->
(elt -> unit Lwt.t) -> (unit -> unit Lwt.t) Lwt.t
watch b p cb watches the log at the path p in the branch b. On each append of a message m to the log, the callback function cb m is invoked. Before installing watches, a listener thread must be started with Ezirmin.Repo.install_listener that watches the store for changes.
Returns a function to disable the watch.