Mavryk_store_unix.Floating_block_storePersistent block store with arborescent history
The floating block store is an append-only store where blocks are stored arbitrarily. This structure possess an indexed map Block_hash.t -> (offset × predecessors x resulting_context_hash) which points to its offset in the associated file along with an exponential list of predecessors block hashes (as implemented in Block_store.compute_predecessors) and the block's resulting context hash. The structure access/modification is protected by a mutex (Lwt_idle_waiter) and thus can be manipulated concurrently. Stored blocks may or may not contain metadata. The instance maintains an opened file descriptor. Therefore it must be properly closed or it might lead to a file descriptor leak.
Four different kind of instances are allowed to co-exist for an identical path: - RO, a read-only instance; - RW, a read-write instance - RO_TMP, RW_TMP, read-write instances; - Restore is a generic instance used to wrap leftover instances while fixing a crashed storage. See Block_store.
This store is expected to respect the following invariant:
The floating block store is composed of the following files:
Block_repr.t:| <block> * |
where <kind> is RO(_TMP), RW(_TMP) (see Naming) and <block>, a Block_repr.t value encoded using Block_repr.encoding (thus prefixed by the its size).
type floating_kind = Mavryk_store_shared.Naming.floating_kind = | RO| RW| RW_TMP| RO_TMP| Restore of floating_kindThe type for the kind of floating store opened.
type info = {predecessors : Mavryk_base.TzPervasives.Block_hash.t list;resulting_context_hash : Mavryk_base.TzPervasives.Context_hash.t;}The type for informations stored in floating store indexes.
The default value of the floating blocks cache size used by index library.
val kind : t -> floating_kindkind floating_store returns the floating store's kind.
val mem : t -> Mavryk_base.TzPervasives.Block_hash.t -> bool Lwt.tmem floating_store hash tests whether hash is stored in floating_store.
val find_info : t -> Mavryk_base.TzPervasives.Block_hash.t -> info option Lwt.tfind_info floating_store block_hash reads from the index the info of block_hash if the block is stored in floating_store, returns None otherwise.
val find_predecessors :
t ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_base.TzPervasives.Block_hash.t list option Lwt.tfind_predecessors floating_store block_hash reads from the index the list of block_hash's predecessors if the block is stored in floating_store, returns None otherwise.
val find_resulting_context_hash :
t ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_base.TzPervasives.Context_hash.t option Lwt.tfind_resulting_context_hash floating_store block_hash reads from the index the resulting context hash if the block is stored in floating_store, returns None otherwise.
val read_block :
t ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_store_shared.Block_repr.t option Lwt.tread_block floating_store hash reads from the file the block of hash if the block is stored in floating_store, returns None otherwise.
val read_block_and_info :
t ->
Mavryk_base.TzPervasives.Block_hash.t ->
(Mavryk_store_shared.Block_repr.t * info) option Lwt.tread_block_and_info floating_store hash same as read_block but also returns the block's info. Returns None if it fails to resolve the given hash.
val append_block :
t ->
?flush:bool ->
?log_metrics:bool ->
info ->
Mavryk_store_shared.Block_repr.block ->
unit Mavryk_base.TzPervasives.tzresult Lwt.tappend_block floating_store ?flush ?log_metrics info block stores the block in floating_store updating its index with the given info and flushing if flush is set to true (defaults to true). log_metrics enables logs of the amount of written bytes using the node's metrics.
val append_all :
t ->
(Mavryk_store_shared.Block_repr.t * info) Mavryk_base.TzPervasives.Seq.t ->
unit Mavryk_base.TzPervasives.tzresult Lwt.tappend_all floating_store chunk stores the chunk of (blocks x info) in floating_store updating its index accordingly.
val iter_s_raw_fd :
(Mavryk_store_shared.Block_repr.t ->
unit Mavryk_base.TzPervasives.tzresult Lwt.t) ->
Lwt_unix.file_descr ->
unit Mavryk_base.TzPervasives.tzresult Lwt.titer_s_raw_fd f fd unsafe sequential iterator on a file descriptor fd. Applies f on every block encountered.
Warning: should be used for internal use only (e.g. snapshots).
val fold_left_s :
('a ->
Mavryk_store_shared.Block_repr.block ->
'a Mavryk_base.TzPervasives.tzresult Lwt.t) ->
'a ->
t ->
'a Mavryk_base.TzPervasives.tzresult Lwt.tfold_left_s f e floating_store sequential fold left on the floating_store using f on every block and e as initial element. The function f is given the last read block.
val fold_left_with_info_s :
('a ->
(Mavryk_store_shared.Block_repr.block * info) ->
'a Mavryk_base.TzPervasives.tzresult Lwt.t) ->
'a ->
t ->
'a Mavryk_base.TzPervasives.tzresult Lwt.tfold_left_with_info_s f e floating_store sequential fold left on the floating_store using f on every block and e as initial element. The function f is given the last read block along with its info.
val iter_s :
(Mavryk_store_shared.Block_repr.t ->
unit Mavryk_base.TzPervasives.tzresult Lwt.t) ->
t ->
unit Mavryk_base.TzPervasives.tzresult Lwt.titer_s f floating_store sequential iterator on the floating_store. Applies f on every block read.
val iter_with_info_s :
((Mavryk_store_shared.Block_repr.t * info) ->
unit Mavryk_base.TzPervasives.tzresult Lwt.t) ->
t ->
unit Mavryk_base.TzPervasives.tzresult Lwt.titer_with_info_s f floating_store sequential iterator on the floating_store. Applies f on every block (and its info) read.
val init :
[ `Chain_dir ] Mavryk_store_shared.Naming.directory ->
readonly:bool ->
floating_kind ->
t Lwt.tinit ~chain_dir ~readonly kind creates or load an existing floating store at path chain_dir with kind.
Warning If readonly is not set, a RO instance is writable.
val close : t -> unit Lwt.tclose floating_store closes floating_store by closing the index and the associated opened file descriptor.
val delete_files : t -> unit Lwt.tdelete_files store closes the store then deletes its content.
swap ~src ~dst closes src and dst then overwrites dst files with src's ones.
Warning Non-atomic swap.
val append_floating_store :
from:t ->
into:t ->
unit Mavryk_base.TzPervasives.tzresult Lwt.tappend_floating_store ~from ~into takes two opened floating block stores and appends all blocks contained in from to into.
Integrity checks
val all_files_exists :
[ `Chain_dir ] Mavryk_store_shared.Naming.directory ->
floating_kind ->
bool Lwt.tall_files_exists ~chain_dir kind checks that the files to the associated kind of floating store are present in the chain_dir directory.
val fix_integrity :
[ `Chain_dir ] Mavryk_store_shared.Naming.directory ->
floating_kind ->
unit Mavryk_base.TzPervasives.tzresult Lwt.tfix_integrity ~chain_dir kind error fixes the integrity of the floating block stores by removing corrupted data and restoring a consistent state.