Skip to main content

nodedb_lite/engine/fts/
state.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Shared runtime state for FTS on Lite.
4//!
5//! Held as `Arc<FtsState>` on both `NodeDbLite` (user-facing entry points)
6//! and `LiteQueryEngine` (PhysicalPlan executor) so the physical visitor
7//! can run text ops without re-architecting the engine boundary.
8
9use std::sync::atomic::AtomicBool;
10use std::sync::{Arc, Mutex};
11
12use nodedb_mem::MemoryGovernor;
13
14use super::manager::FtsCollectionManager;
15
16/// Type alias for Lite's persistent FTS index (serialized to KV store on flush).
17pub type LiteFtsIndex = super::FtsIndex<super::MemoryBackend>;
18
19/// Arc-shareable wrapper around the per-collection FTS manager.
20///
21/// FTS is not storage-parameterised — the manager uses an in-memory backend
22/// independent of `S`. No generic parameter is needed here.
23pub struct FtsState {
24    pub(crate) manager: Mutex<FtsCollectionManager>,
25    pub(super) mutation_gate: Arc<tokio::sync::Mutex<()>>,
26    pub(super) checkpoint_trusted: AtomicBool,
27}
28
29impl FtsState {
30    /// Create a new, empty `FtsState` bound to `governor` for memory accounting.
31    pub fn new(governor: Arc<MemoryGovernor>) -> Self {
32        Self {
33            manager: Mutex::new(FtsCollectionManager::new(governor)),
34            mutation_gate: Arc::new(tokio::sync::Mutex::new(())),
35            checkpoint_trusted: AtomicBool::new(false),
36        }
37    }
38
39    /// Wrap an already-restored `FtsCollectionManager`.
40    pub fn from_restored(manager: FtsCollectionManager) -> Self {
41        Self {
42            manager: Mutex::new(manager),
43            mutation_gate: Arc::new(tokio::sync::Mutex::new(())),
44            checkpoint_trusted: AtomicBool::new(false),
45        }
46    }
47}