package octez-libs
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=aa2f5bc99cc4ca2217c52a1af2a2cdfd3b383208cb859ca2e79ca0903396ca1d
sha512=d68bb3eb615e3dcccc845fddfc9901c95b3c6dc8e105e39522ce97637b1308a7fa7aa1d271351d5933febd7476b2819e1694f31198f1f0919681f1f9cc97cb3a
doc/octez-libs.stdlib-unix/Tezos_stdlib_unix/Key_value_store/index.html
Module Tezos_stdlib_unix.Key_value_storeSource
This error is returned when the requested data is not found.
Key-value store
This module defines a simple key-value store. The design is minimal and aims to be:
- easy to use
- safe when used in a concurrent setting
This key-value store also features a best effort mechanism relying on a cache to avoid I/Os.
This key-value store assumes keys have a flat structure with a first layer of virtual directories and fixed-size virtual files in each directory. Each virtual directory is backed by a single physical file. Values are stored in virtual files, which are mapped sequentially in their virtual directory.
An abstract representation of a key-value store.
A directory_spec specifies the layout of virtual files storing data of type 'value, as well as the name of the underlying physical file.
val directory :
?encoded_value_size:int ->
'value Data_encoding.t ->
string ->
('value -> 'value -> bool) ->
('file -> int) ->
('file, 'value) directory_specdirectory ?encoded_value_size value_encoding path eq index_of describes a virtual directory.
encoded_value_sizeis the size in bytes of values encoded withvalue_encoding. Ifvalue_encodingdoes not respect this property, the behaviour of the store is undefined. Ifencoded_value_sizeis not given,value_encodingmust be of fixed length.value_encodingis an encoding for the content of virtual files.pathis the path of the physical file in which the directory is to be stored.eqis an equality function on the contents of virtual files.index_ofgives the index of a given file in the directory.
val init :
lru_size:int ->
('dir -> ('file, 'value) directory_spec) ->
('dir, 'file, 'value) tinit ~lru_size directory_of initialises a key-value store. This is a design where each directory is stored into a single file.
For each virtual directory, we use directory_of to get its specification, including its physical location and how data is layed out in its backing file.
lru_size is a parameter that represents the number of different values that can be in memory. It is up to the user of this library to decide this number depending on the sizes of the values.
close kvs waits until all pending reads and writes are completed and closes the key-value store.
val write_value :
?override:bool ->
('dir, 'file, 'value) t ->
'dir ->
'file ->
'value ->
unit Tezos_error_monad.Error_monad.tzresult Lwt.twrite_value ?(override=false) t key value writes a value in the key value store. If a previous writing or read failed, the function will try again to write the value. If override is true, the value will be written even though there is already a written value for this key.
val write_values :
?override:bool ->
('dir, 'file, 'value) t ->
('dir * 'file * 'value) Tezos_error_monad.TzLwtreslib.Seq.t ->
unit Tezos_error_monad.Error_monad.tzresult Lwt.twrite_values ?(override=false) t seq writes a sequence of keys values onto the store (see write_value). If an error occurs, the first error is returned. This function guarantees that up to the data for which the error occured, the values where stored onto the disk.
val read_value :
('dir, 'file, 'value) t ->
'dir ->
'file ->
'value Tezos_error_monad.Error_monad.tzresult Lwt.tread_value t key reads the value associated to key in the store. Fails if no value where attached to this key. The value read is the last one that was produced by a successful write.
val read_values :
('dir, 'file, 'value) t ->
('dir * 'file) Tezos_error_monad.TzLwtreslib.Seq.t ->
('dir * 'file * 'value Tezos_error_monad.Error_monad.tzresult)
Tezos_error_monad.TzLwtreslib.Seq_s.tread_values t keys produces a sequence of values associaed to the sequence of keys. This function is almost instantaneous since no reads are performed. Reads are done when the caller consumes the values of the sequence returned.