armdb 0.15.3

sharded bitcask key-value storage optimized for NVMe
Documentation
//! Segmented append-only collection family.
//!
//! Spec: `docs/superpowers/specs/26-09-29-segmented-append-only-collection.md`.

/// A process-loss injection point. Compiles to nothing outside tests and the
/// `test-faults` feature.
macro_rules! failpoint {
    ($stage:ident) => {
        #[cfg(any(test, feature = "test-faults"))]
        $crate::seg::failpoints::hit($crate::seg::failpoints::$stage);
    };
}
pub(crate) use failpoint;

pub(crate) mod block;
pub(crate) mod cache;
pub(crate) mod config;
pub(crate) mod core;
#[cfg(any(test, feature = "test-faults"))]
#[doc(hidden)]
pub mod failpoints;
pub(crate) mod filter;
pub(crate) mod freeze;
pub(crate) mod fs;
pub(crate) mod generation;
pub(crate) mod hash;
pub(crate) mod index_migration;
pub(crate) mod index_target;
pub(crate) mod key_index;
pub(crate) mod manifest;
pub(crate) mod map;
#[cfg(test)]
#[cfg(feature = "segmented")]
mod model_tests;
pub(crate) mod ordered;
#[cfg(test)]
mod ordered_tests;
pub(crate) mod page_index;
pub(crate) mod projections;
pub(crate) mod query;
pub(crate) mod residency;
pub(crate) mod scan;
#[cfg(test)]
mod scenario_tests;
pub(crate) mod seal;
pub(crate) mod segment;
pub(crate) mod sidecar;
pub(crate) mod skeleton;
#[cfg(test)]
pub(crate) mod testkit;
pub(crate) mod tree;
pub(crate) mod verify;
pub(crate) mod worker;

pub use config::SegConfig;
pub use core::SegMeta;
pub use index_target::IndexState;
pub use map::SegMap;
pub use query::SegRange;
pub use tree::{SegIter, SegKeyIter, SegTree, SegTreeMeta};
pub use verify::{SegStats, SegmentInfo, VerifyProblem, VerifyReport, VerifyScope};
pub use worker::SealStatus;

use std::path::Path;

use crate::error::DbError;

/// What a pure parser found wrong with the bytes it was given.
///
/// Parsers do not know which file the bytes came from. The caller that does
/// know turns a fault into a [`DbError`] with [`FormatFault::into_db`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum FormatFault {
    /// Well formed, but written by a format this build does not read.
    Unsupported(String),
    /// Damaged: a checksum, a length or an ordering rule does not hold.
    Corrupt(String),
}

impl FormatFault {
    pub(crate) fn unsupported(msg: impl Into<String>) -> Self {
        Self::Unsupported(msg.into())
    }

    pub(crate) fn corrupt(msg: impl Into<String>) -> Self {
        Self::Corrupt(msg.into())
    }

    pub(crate) fn into_db(self, segment_id: u64, block: Option<u32>, path: &Path) -> DbError {
        match self {
            Self::Unsupported(reason) => {
                DbError::FormatMismatch(format!("{}: {reason}", path.display()))
            }
            Self::Corrupt(reason) => DbError::SegmentCorrupt {
                segment_id,
                block,
                path: path.to_path_buf(),
                reason,
            },
        }
    }
}