package chamelon

  1. Overview
  2. Docs

Parameters

module Clock : Mirage_clock.PCLOCK

Signature

include Mirage_kv.RW

Read-write Stores

There is a trade-off between durability and performance. If you want performance, use the batch operation with a chain of sets and removes. They will be applied on the underlying storage layer all at once. Otherwise set and remove will cause a flush in the underlying storage layer every time, which could degrade performance.

include Mirage_kv.RO

Read-only key-value stores

type nonrec error = private [>
  1. | Mirage_kv.error
]

The type for errors.

val pp_error : error Fmt.t

pp_error is the pretty-printer for errors.

type t

The type representing the internal state of the key-value store.

val disconnect : t -> unit Lwt.t

Disconnect from the key-value store. While this might take some time to complete, it can never result in an error.

type key = Mirage_kv.Key.t

The type for keys.

val exists : t -> key -> ([ `Value | `Dictionary ] option, error) Stdlib.result Lwt.t

exists t k is Some `Value if k is bound to a value in t, Some `Dictionary if k is a prefix of a valid key in t and None if no key with that prefix exists in t.

exists answers two questions: does the key exist and is it referring to a value or a dictionary.

An error occurs when the underlying storage layer fails.

val get : t -> key -> (string, error) Stdlib.result Lwt.t

get t k is the value bound to k in t.

The result is Error (`Value_expected k) if k refers to a dictionary in t.

val list : t -> key -> ((string * [ `Value | `Dictionary ]) list, error) Stdlib.result Lwt.t

list t k is the list of entries and their types in the dictionary referenced by k in t.

The result is Error (`Dictionary_expected k) if k refers to a value in t.

val last_modified : t -> key -> (int * int64, error) Stdlib.result Lwt.t

last_modified t k is the last time the value bound to k in t has been modified.

The modification time (d, ps) is a span for the signed POSIX picosecond span d * 86_400e12 + ps. d is a signed number of POSIX days and ps a number of picoseconds in the range [0;86_399_999_999_999_999L].

When the value bound to k is a dictionary, the modification time is the latest modification of all entries in that dictionary. This behaviour is only one level deep and not recursive.

val digest : t -> key -> (string, error) Stdlib.result Lwt.t

digest t k is the unique digest of the value bound to k in t.

When the value bound to k is a dictionary, the digest is a unique and deterministic digest of its entries.

type nonrec write_error = private [>
  1. | Mirage_kv.write_error
]

The type for write errors.

val pp_write_error : write_error Fmt.t

The pretty-printer for pp_write_error.

val set : t -> key -> string -> (unit, write_error) Stdlib.result Lwt.t

set t k v replaces the binding k -> v in t.

Durability is guaranteed unless set is run inside an enclosing batch operation, where durability will be guaranteed at the end of the batch.

val remove : t -> key -> (unit, write_error) Stdlib.result Lwt.t

remove t k removes any binding of k in t. If k was bound to a dictionary, the full dictionary will be removed.

Durability is guaranteed unless remove is run inside an enclosing batch operation, where durability will be guaranteed at the end of the batch.

val batch : t -> ?retries:int -> (t -> 'a Lwt.t) -> 'a Lwt.t

batch t f run f in batch. Ensure the durability of operations.

Since a batch is applied at once, the readings inside a batch will return the state before the entire batch. Concurrent operations will not affect other ones executed during the batch.

Batch applications can fail to apply if other operations are happening concurrently. In case of failure, f will run again with the most recent version of t. The result is Error `Too_many_retries if f is run for more then retries attemps (default is 13).

val format : program_block_size:int -> Sectors.t -> (unit, write_error) Stdlib.result Lwt.t
val connect : program_block_size:int -> Sectors.t -> (t, error) Stdlib.result Lwt.t
val size : t -> key -> (int, error) Stdlib.result Lwt.t
val get_partial : t -> key -> offset:int -> length:int -> (string, error) Stdlib.result Lwt.t

get_partial t k ~offset ~length gives errors for length <= 0 and offset < 0. * get_partial t k ~offset ~length, if successful, gives a result of (Ok v) where String.length v <= length. If offset + length is greater than the file length, (Ok v) is returned where v's first byte is offset and its last byte is the last byte in the file.

OCaml

Innovation. Community. Security.