plebeia
Library
Module
Module type
Parameter
Class
Class type
Reader: Read only mode. Multiple readers can exist.
Writer: Read write mode. Only 1 writer can exist for a storage.
Private : Modifications are private. See MAP_PRIVATE of the document of mmap()
type config = {
head_string : string; | (* exactly 20 bytes *) |
version : int; | |
bytes_per_cell : int; | |
max_index : Index.t; |
}
type t = storage
The type
2 Open, close, and commit
Create a new storage
* length: The initial size of the storage in cells * resize_step: How many cells allocated for each resize * version: Default is Verison.version * string : The path name
Open an existing storage
val null : t
Dummy storage
val is_null : t -> bool
Truncate the data file and reinitialize it. All the contents are lost. length
is the initial reserved size of the reinitialized file.
For reader to update the storage to catch up the update by the writer process. For Writer and Private, it does nothing.
Write the current state of the storage. Once called, the state is shared with the reader processes with process sync enabled.
Note that commit
does NOT assure the persistence of the data after a system crash. Use flush
to make it persistent even after a crash.
Flushes all the added data to the disk. The data added to the storage before the call of flush
are persisted even after a system crash. Data added after the last call of flush
may be lost after a system crash.
flush
may trigger huge disk writes. Too frequent call of flush
may degrates the performance.
val enable_process_sync : t -> unit
For readers. Enable the process synchronization between the writer process. Once enabled, update_reader
checks the header for the process sync instead of the disk sync, and they do not need to wait a call of flush
in the writer.
Do NOT call this function before the writer calls commit
. Otherwise readers can misuse an invalid header value. You would need some process communication betweeh the writer and readers for this, which is not provided by Plebeia.
2 Accessor
val filename : t -> string
Return the file name
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
Used cells in bytes
val version : t -> int
Storage version
val override_version : t -> int -> unit
Override the header version of the file
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 -> Index.t -> Mmap.Buffer.t
Get the content of the cell specified by the index
val get_cell2 : t -> Index.t -> Mmap.Buffer.t
make a 2-cell-wide writable buffer from the beginning of the cell of the given index
val get_bytes : t -> Index.t -> int -> Mmap.Buffer.t
Get the contiguous bytes from the head of the index
Allocate cells and return the first index
module Chunk : sig ... end
Bigger data than a cell
module Internal : sig ... end