package plebeia

  1. Overview
  2. Docs

Module Internal.StorageSource

1 Fixed size storage on a file

The Storage has fixed 32-byte size cells.

2 Types

Sourcetype mode =
  1. | Private
    (*

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

    *)
  2. | Reader
    (*

    Reader

    *)
  3. | Writer
    (*

    Writer. Only one writer can exist.

    *)
Sourcetype storage
Sourcetype t = storage

The type

2 Open, close, and commit

Sourceval 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

Sourceval open_ : ?pos:int64 -> ?resize_step:Plebeia__.Index.t -> mode:mode -> string -> t

Open an existing storage

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

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

Sourceval close : t -> unit

Close the storage

Sourceval 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

Sourceval filename : t -> string

Return the file name

Sourceval mode : t -> mode

Return the opening mode

Sourceval get_version : t -> int

Get the file version

Sourceval get_last_root_index : t -> Plebeia__.Index.t option
Sourceval 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.

Sourceval size : t -> Int64.t

In bytes

Sourceval 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

Sourceval get_cell : t -> Plebeia__.Index.t -> Cstruct.t

Get the content of the cell specified by the index

Sourceval get_bytes : t -> Plebeia__.Index.t -> int -> Cstruct.t

Get the contiguous bytes from the head of the index

Sourceval new_index : t -> Plebeia__.Index.t

Allocate a cell and returns its index

Sourceval new_indices : t -> int -> Plebeia__.Index.t

Allocate cells and return the first index

Sourceval make_buf : t -> Plebeia__.Index.t -> Cstruct.t

make a writable buffer of the cell of the given index

Sourceval make_buf2 : t -> Plebeia__.Index.t -> Cstruct.t

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

Sourcemodule Chunk : sig ... end

Bigger data than a cell

OCaml

Innovation. Community. Security.