plebeia

Merkle Patricia tree implementation
Library plebeia
Module Plebeia . Internal . Storage

2 Types

type mode =
| Private(*

Private writer. The file is never modified. Modification to files by other writers may cause unspecified read result of Private.

*)
| Reader(*

Reader

*)
| Writer(*

Writer. Only one writer can exist.

*)
type storage
type t = storage

The type

2 Open, close, and commit

val create : ?pos:int64 -> ?length:int -> ?resize_step:Plebeia__Index.t -> string -> t

Create a new storage

* pos : Where to start the storage in the file, in bytes. * length: The initial size of the storage, excluding pos. * resize_step: How many cells allocated for each resize * string : The path name

val open_ : ?pos:int64 -> ?resize_step:Plebeia__Index.t -> mode:mode -> string -> t

Open an existing storage

val truncate : ?length:int -> t -> unit

Truncate the data file and reinitialize it. All the contents are lost. length is the initial reserved size of the reinitialized file.

val sync : t -> unit

For reader to update the storage to catch up the update by the writer process. For Writer and Private, it does nothing.

val close : t -> unit

Close the storage

val commit : t -> unit

Write the current state of the storage at its header. If the system crashes, any updates to the storage after the last commit will be lost, even if they are written to the file.

2 Accessor

val filename : t -> string

Return the file name

val mode : t -> mode

Return the opening mode

val get_version : t -> int

Get the file version

val get_last_root_index : t -> Plebeia__Index.t option
val get_current_length : t -> Plebeia__Index.t

Get the status of the storage

For Reader, it only returns the lastest information it knows in memory. Writer may already update this information on the disk.

val size : t -> Int64.t

In bytes

val set_last_root_index : t -> Plebeia__Index.t option -> unit

Set the last index of root hash. Note that the data are only saved to the file when Header.commit is called.

2 Read and write

val get_cell : t -> Plebeia__Index.t -> Cstruct.t

Get the content of the cell specified by the index

val get_bytes : t -> Plebeia__Index.t -> int -> Cstruct.t

Get the contiguous bytes from the head of the index

val new_index : t -> Plebeia__Index.t

Allocate a cell and returns its index

val new_indices : t -> int -> Plebeia__Index.t

Allocate cells and return the first index

val make_buf : t -> Plebeia__Index.t -> Cstruct.t

make a writable buffer of the cell of the given index

val make_buf2 : t -> Plebeia__Index.t -> Cstruct.t

make a 64 bytes writable buffer from the beginning of the cell of the given index

module Chunk : sig ... end

Bigger data than a cell