armdb 0.15.0

sharded bitcask key-value storage optimized for NVMe
Documentation
//! The index-target role of a `SegTree` and its persisted lifecycle state.
use std::sync::atomic::{AtomicU8, Ordering};

/// The persisted lifecycle state of a managed index target.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum IndexState {
    /// Not built yet, or a build or a typed migration of its source has not finished.
    Pending = 0,
    /// Complete: maintained by its source.
    Ready = 1,
    /// An old index version; no longer maintained.
    Retired = 2,
}

/// Shared between the target handle and the `Db`, which updates it.
pub(crate) struct IndexStateCell(AtomicU8);

impl IndexStateCell {
    pub(crate) fn new(state: IndexState) -> Self {
        Self(AtomicU8::new(state as u8))
    }

    pub(crate) fn get(&self) -> IndexState {
        match self.0.load(Ordering::Acquire) {
            0 => IndexState::Pending,
            1 => IndexState::Ready,
            _ => IndexState::Retired,
        }
    }

    pub(crate) fn set(&self, state: IndexState) {
        self.0.store(state as u8, Ordering::Release);
    }
}

pub(crate) const DIRECT_WRITE: &str =
    "an index target takes no direct writes; its source's projection writes it";
pub(crate) const NO_RETENTION: &str = "an index target cannot use retention";
pub(crate) const NO_DROP: &str = "an index target cannot drop segments";
pub(crate) const KEEP_ONLY: &str = "an index target's own typed migration may only return Keep; change the source's projection instead";
pub(crate) const NO_HOOK: &str = "an index target takes no hook";