pub struct Engine { /* private fields */ }Expand description
The Noxu DB engine.
Wires together all internal subsystems:
- EnvironmentImpl (dbi layer)
- Evictor (cache management)
- Cleaner (log GC)
- Checkpointer (durability)
- DaemonManager (background threads)
This is the internal engine that noxu-db wraps. It coordinates
all subsystems and provides a unified interface for database operations.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn open(config: EngineConfig) -> Result<Self>
pub fn open(config: EngineConfig) -> Result<Self>
Opens a Noxu DB environment with the given configuration.
This is the main entry point for opening an environment. It:
- Validates configuration
- Creates the environment directory if needed
- Creates EnvironmentImpl (dbi layer)
- Creates Evictor, Cleaner, Checkpointer
- Runs recovery (RecoveryManager)
- Starts daemon threads
- Returns the Engine
§Errors
Returns an error if:
- Configuration is invalid
- Environment directory cannot be created
- Recovery fails
- Any subsystem initialization fails
Sourcepub fn close(&self) -> Result<()>
pub fn close(&self) -> Result<()>
Closes the environment.
Performs orderly shutdown:
- Stop engine daemon threads
- Flush final checkpoint
- Close
EnvironmentImpl(stops its own daemons, forces a final checkpoint, and fsyncs the WAL)
After close(), the Engine cannot be used. Dropping the Engine
afterwards relies on EnvironmentImpl’s own RAII Drop as a backstop;
EnvironmentImpl::close is idempotent, so the explicit call here and
the eventual Drop do not conflict.
Sourcepub fn get_env_impl(&self) -> &Arc<Mutex<EnvironmentImpl>>
pub fn get_env_impl(&self) -> &Arc<Mutex<EnvironmentImpl>>
Gets a reference to the EnvironmentImpl.
Sourcepub fn get_evictor(&self) -> &Arc<Evictor>
pub fn get_evictor(&self) -> &Arc<Evictor>
Gets a reference to the Evictor.
Sourcepub fn get_cleaner(&self) -> &Arc<Cleaner>
pub fn get_cleaner(&self) -> &Arc<Cleaner>
Gets a reference to the Cleaner.
Sourcepub fn get_checkpointer(&self) -> &Arc<Checkpointer>
pub fn get_checkpointer(&self) -> &Arc<Checkpointer>
Gets a reference to the Checkpointer.
Sourcepub fn get_config(&self) -> &EngineConfig
pub fn get_config(&self) -> &EngineConfig
Gets the engine configuration.
Sourcepub fn checkpoint(&self, invoker: &str) -> Result<CheckpointResult>
pub fn checkpoint(&self, invoker: &str) -> Result<CheckpointResult>
Performs a checkpoint.
§Arguments
invoker- Description of who invoked the checkpoint (for logging)
§Returns
Information about the checkpoint that was performed.
§Errors
EngineError::EnvironmentClosedif the engine has been closed.EngineError::InvalidConfigif the engine is opened read-only.- Any error returned by the underlying checkpointer
(e.g.
EngineError::DatabaseErrorpropagated from log/tree I/O).
Sourcepub fn clean(&self, n_files: u32) -> Result<CleanResult>
pub fn clean(&self, n_files: u32) -> Result<CleanResult>
Performs log cleaning.
§Arguments
n_files- Maximum number of files to clean
§Returns
Information about the cleaning operation.
§Errors
EngineError::EnvironmentClosedif the engine has been closed.EngineError::InvalidConfigif the engine is opened read-only.EngineError::DatabaseErrorfor any I/O or tree error returned by the underlying cleaner.
Sourcepub fn clean_adaptive(&self) -> Result<(CleanResult, u64)>
pub fn clean_adaptive(&self) -> Result<(CleanResult, u64)>
Throttle-driven cleaning pass for use by the cleaner daemon.
Reads the current log write-byte counter, updates the throttle, then
cleans n_files recommended by the throttle.
Returns (CleanResult, sleep_ms) — the daemon should sleep
sleep_ms milliseconds before its next pass.
§Errors
EngineError::EnvironmentClosedif the engine has been closed.EngineError::InvalidConfigif the engine is opened read-only.EngineError::DatabaseErrorfor any I/O or tree error returned by the underlying cleaner.
Sourcepub fn evict(&self) -> Result<EvictResult>
pub fn evict(&self) -> Result<EvictResult>
Performs cache eviction.
§Returns
Information about the eviction operation.
§Errors
EngineError::EnvironmentClosedif the engine has been closed.
Sourcepub fn get_stats(&self) -> EnvironmentStats
pub fn get_stats(&self) -> EnvironmentStats
Collects environment statistics.
Returns a snapshot of statistics from all subsystems.
Sourcepub fn get_cache_usage(&self) -> u64
pub fn get_cache_usage(&self) -> u64
Gets the current cache usage in bytes.
Sourcepub fn get_cache_budget(&self) -> u64
pub fn get_cache_budget(&self) -> u64
Gets the cache budget in bytes.
Sourcepub fn is_cache_over_budget(&self) -> bool
pub fn is_cache_over_budget(&self) -> bool
Checks if the cache is over budget.