nodedb-lite 0.1.0

Embedded edge client for NodeDB — offline vector search, graph traversal, and CRDT sync
Documentation
// SPDX-License-Identifier: Apache-2.0

//! Shared runtime state for FTS on Lite.
//!
//! Held as `Arc<FtsState>` on both `NodeDbLite` (user-facing entry points)
//! and `LiteQueryEngine` (PhysicalPlan executor) so the physical visitor
//! can run text ops without re-architecting the engine boundary.

use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex};

use nodedb_mem::MemoryGovernor;

use super::manager::FtsCollectionManager;

/// Type alias for Lite's persistent FTS index (serialized to KV store on flush).
pub type LiteFtsIndex = super::FtsIndex<super::MemoryBackend>;

/// Arc-shareable wrapper around the per-collection FTS manager.
///
/// FTS is not storage-parameterised — the manager uses an in-memory backend
/// independent of `S`. No generic parameter is needed here.
pub struct FtsState {
    pub(crate) manager: Mutex<FtsCollectionManager>,
    pub(super) mutation_gate: Arc<tokio::sync::Mutex<()>>,
    pub(super) checkpoint_trusted: AtomicBool,
}

impl FtsState {
    /// Create a new, empty `FtsState` bound to `governor` for memory accounting.
    pub fn new(governor: Arc<MemoryGovernor>) -> Self {
        Self {
            manager: Mutex::new(FtsCollectionManager::new(governor)),
            mutation_gate: Arc::new(tokio::sync::Mutex::new(())),
            checkpoint_trusted: AtomicBool::new(false),
        }
    }

    /// Wrap an already-restored `FtsCollectionManager`.
    pub fn from_restored(manager: FtsCollectionManager) -> Self {
        Self {
            manager: Mutex::new(manager),
            mutation_gate: Arc::new(tokio::sync::Mutex::new(())),
            checkpoint_trusted: AtomicBool::new(false),
        }
    }
}