Skip to main content

SimFilesystem

Struct SimFilesystem 

Source
pub struct SimFilesystem { /* private fields */ }
Expand description

A filesystem in memory that records what was done to it.

Cloning one gives another handle on the same filesystem, not a copy of it, which is what makes it usable in the places a real one would be shared.

Implementations§

Source§

impl SimFilesystem

Source

pub fn new() -> Self

An empty filesystem.

Source

pub fn ops(&self) -> Vec<Op>

Everything that has been done to this filesystem, in order.

Source

pub fn op_count(&self) -> usize

How many operations have been recorded.

This is the count the failure point enumeration in section 16.5 runs over: record a workload, then rerun it once per index with the failure injected there.

Source

pub fn clear_log(&self)

Forgets the recorded operations, keeping the contents.

For a test that has to set up a database and only wants to enumerate failure points over what comes after the setup.

Source

pub fn fail_at(&self, index: usize)

Makes the operation at index fail once.

This is error path testing and it is a different mechanism from Self::crash, on purpose. An EIO on one write is a thing the caller has to handle and keep running from. A crash is a thing the caller does not get to handle at all, and the question there is what the next process to open the file sees. Conflating them produces a test that proves neither.

Source

pub fn clear_failure(&self)

Cancels an injected failure that has not fired.

Source

pub fn reads_served(&self) -> u64

How many reads have been served since this filesystem was made.

This is the number the read faults below are addressed by, and it is also the byte counting hook’s coarser sibling: a reader that reads a row group it should have pruned makes more reads than one that does not, and the count says so whatever the answer was.

Source

pub fn short_read_at(&self, read: u64, len: usize)

Makes read number read come back with len bytes rather than the length asked for.

A short read is not an error, it is a short read, and the reason it is worth injecting is that a decoder which treats a returned buffer as full reads whatever was in the buffer before, which is a wrong answer and not a crash.

Source

pub fn fail_read_at(&self, read: u64)

Makes read number read fail.

Once, like Self::fail_at, and for the same reason: the interesting question is whether the caller survives one failure, not whether it survives a disk that is gone.

Source

pub fn complete(&self, order: Completions)

Sets the order a batch handed to submit comes back in.

Source

pub fn clear_read_faults(&self)

Cancels every injected read fault and puts completions back in submission order.

Source

pub fn pending(&self) -> Vec<(u64, PathBuf)>

The writes that have been issued and not made durable, as sequence numbers with their file.

These are the numbers Crash::Keeping takes. The order is the order they were issued in, across all files, because two writes to different files race with each other exactly the way two writes to one file do.

Source

pub fn crash(&self, crash: &Crash) -> Self

The filesystem a process would find after a crash.

The durable image, plus whichever pending writes crash says survived, applied in the order they were issued. The result is a fresh filesystem with an empty log, because the log belongs to the process that died.

Source

pub fn durable_contents(&self, path: &Path) -> Option<Vec<u8>>

The durable contents of a file, ignoring anything unsynced.

For a test that wants to assert what is on the disk without going through a crash first.

Source

pub fn contents(&self, path: &Path) -> Option<Vec<u8>>

The contents a reader would see right now, unsynced writes included.

Trait Implementations§

Source§

impl Clone for SimFilesystem

Source§

fn clone(&self) -> SimFilesystem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SimFilesystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SimFilesystem

Source§

fn default() -> SimFilesystem

Returns the “default value” for a type. Read more
Source§

impl Filesystem for SimFilesystem

Source§

fn open(&self, path: &Path, mode: OpenMode) -> Result<Box<dyn File>>

Opens a file. Read more
Source§

fn exists(&self, path: &Path) -> bool

Whether a path exists.
Source§

fn is_dir(&self, path: &Path) -> bool

Whether a path is a directory. Read more
Source§

fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>>

What is directly inside a directory, as whole paths rather than as names. Read more
Source§

fn remove(&self, path: &Path) -> Result<()>

Deletes a file. Read more
Source§

fn rename(&self, from: &Path, to: &Path) -> Result<()>

Moves a file, replacing the destination if it exists. Read more
Source§

fn create_dir_all(&self, path: &Path) -> Result<()>

Creates a directory and any missing parents. Read more
Source§

fn sync_dir(&self, path: &Path) -> Result<()>

Makes a directory entry durable, which is what a rename needs before it counts. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.