package granary

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Granary_unix.Fault_injectSource

Fault-injecting wrapper around Unix_file for crash-recovery tests.

Fault-injecting wrapper around the Unix_file block backend.

Wraps the standard block callbacks; the fail_after_writes counter causes the (N+1)-th write_page call to return Error "injected crash". After failure all subsequent writes also fail (simulating a downed device). Optionally, fail_on_sync forces sync to fail on first invocation.

Recovery correctness (file consistency after a mid-write crash) is NOT in scope for this module — it merely exposes the injection mechanics so that test harnesses can verify the engine does not panic in the face of I/O errors.

Sourcetype t
Sourceval pp : Format.formatter -> t -> unit

Pretty-print a wrapper's write count and fault state.

Sourcetype config = {
  1. fail_after_writes : int option;
  2. fail_on_sync : bool;
}
Sourceval default_config : config

Default: no faults injected.

Sourceval open_with_faults : path:string -> size_bytes:int -> config:config -> (t * (page_id:int64 -> Cstruct.t -> (unit, string) result Lwt.t) * (page_id:int64 -> Cstruct.t -> (unit, string) result Lwt.t) * (unit -> (unit, string) result Lwt.t) * (n_pages:int64 -> (unit, string) result Lwt.t) * int64 * (unit -> unit Lwt.t)) Lwt.t

Build a fault-injecting block backend wrapping a file at path. The file is created if absent and resized to size_bytes bytes. config controls when faults trigger. Returns the wrapper handle along with the callbacks expected by Db.open_block.

The close callback returns unit Lwt.t to match Db.open_block's signature: any error from the underlying Unix_file.close is swallowed (logged-and-discarded) at the wrapper boundary.

Sourceval writes_completed : t -> int

Number of successful underlying writes observed by this wrapper.

Sourceval faulted : t -> bool

Whether the injected fault has tripped.