Skip to main content

fff_search/
db_healthcheck.rs

1use crate::error::Result;
2
3/// Health information about a database
4#[derive(Debug, Clone)]
5pub struct DbHealth {
6    /// Path to the database file
7    pub path: String,
8    /// Size on disk in bytes
9    pub disk_size: u64,
10    /// Entry counts by table name
11    pub entry_counts: Vec<(&'static str, u64)>,
12}
13
14pub trait DbHealthChecker {
15    fn get_env(&self) -> &heed::Env;
16    fn count_entries(&self) -> Result<Vec<(&'static str, u64)>>;
17
18    fn get_health(&self) -> Result<DbHealth> {
19        let env = self.get_env();
20
21        let size = env.real_disk_size().map_err(crate::error::Error::EnvOpen)?;
22        let path = env.path().to_string_lossy().to_string();
23        let entry_counts = self.count_entries()?;
24
25        Ok(DbHealth {
26            path,
27            disk_size: size,
28            entry_counts,
29        })
30    }
31}