Skip to main content

linkrs_storage/engine/persistence/
config.rs

1use std::path::{Path, PathBuf};
2use std::time::Duration;
3
4use linkrs_transaction::wal::SyncPolicy;
5
6use crate::engine::config::PropertyGraphConfig;
7
8#[derive(Debug, Clone)]
9pub struct PersistenceConfig {
10    pub data_dir: PathBuf,
11    pub wal_dir: PathBuf,
12    pub checkpoint_dir: PathBuf,
13    pub snapshot_dir: PathBuf,
14    pub auto_flush_interval: Duration,
15    pub auto_checkpoint_interval: Duration,
16    pub checkpoint_threshold: u64,
17    pub max_wal_size: u64,
18    pub enable_snapshots: bool,
19    pub snapshot_interval: Duration,
20    /// Should WAL be enabled
21    pub enable_wal: bool,
22    /// Synchronization policy for WAL write-ahead logging
23    pub sync_policy: Option<SyncPolicy>,
24    /// Property graph resource and maintenance configuration.
25    pub property_graph_config: PropertyGraphConfig,
26    /// Whether async background checkpoint scheduling is enabled.
27    pub async_checkpoint_enabled: bool,
28    /// Interval for background checkpoint polling.
29    pub async_checkpoint_poll_interval: Duration,
30    /// Per-thread WAL buffer size for async flush (default 256KB).
31    pub wal_buffer_size: usize,
32    /// Background WAL flush interval in milliseconds (default 10ms).
33    pub wal_flush_interval_ms: u64,
34    /// Enable background async WAL flush; false preserves sync behavior.
35    pub wal_enable_async_flush: bool,
36}
37
38impl Default for PersistenceConfig {
39    fn default() -> Self {
40        Self {
41            data_dir: PathBuf::from("data"),
42            wal_dir: PathBuf::from("wal"),
43            checkpoint_dir: PathBuf::from("checkpoint"),
44            snapshot_dir: PathBuf::from("snapshots"),
45            auto_flush_interval: Duration::from_secs(60),
46            auto_checkpoint_interval: Duration::from_secs(300),
47            checkpoint_threshold: 10000,
48            max_wal_size: 100 * 1024 * 1024,
49            enable_snapshots: true,
50            snapshot_interval: Duration::from_secs(3600),
51            enable_wal: true,
52            sync_policy: Some(SyncPolicy::EveryWrite),
53            property_graph_config: PropertyGraphConfig::default(),
54            async_checkpoint_enabled: true,
55            async_checkpoint_poll_interval: Duration::from_secs(1),
56            wal_buffer_size: 256 * 1024,
57            wal_flush_interval_ms: 10,
58            wal_enable_async_flush: true,
59        }
60    }
61}
62
63impl PersistenceConfig {
64    pub fn for_work_dir(path: impl AsRef<Path>) -> Self {
65        let path = path.as_ref();
66        Self {
67            data_dir: path.join("data"),
68            wal_dir: path.join("wal"),
69            checkpoint_dir: path.join("checkpoint"),
70            snapshot_dir: path.join("snapshots"),
71            enable_wal: true,
72            sync_policy: Some(SyncPolicy::EveryWrite),
73            property_graph_config: PropertyGraphConfig::default(),
74            ..Default::default()
75        }
76    }
77
78    pub fn with_property_graph_config(mut self, config: PropertyGraphConfig) -> Self {
79        self.property_graph_config = config;
80        self
81    }
82}