use crate::backend::native::CpuProfile;
use crate::backend::native::v2::wal::checkpoint::CheckpointStrategy;
use std::time::Duration;
#[derive(Clone, Debug)]
pub struct NativeConfig {
pub create_if_missing: bool,
pub reserve_node_capacity: Option<usize>,
pub reserve_edge_capacity: Option<usize>,
pub cpu_profile: Option<CpuProfile>,
pub max_parallel_transactions: usize,
pub checkpoint_strategy: Option<CheckpointStrategy>,
}
impl Default for NativeConfig {
fn default() -> Self {
Self {
create_if_missing: true,
reserve_node_capacity: None,
reserve_edge_capacity: None,
cpu_profile: None,
max_parallel_transactions: 4, checkpoint_strategy: None, }
}
}
impl NativeConfig {
pub fn effective_cpu_profile(&self) -> CpuProfile {
if let Ok(env_profile) = std::env::var("SQLITEGRAPH_NATIVE_CPU_PROFILE") {
if let Ok(profile) = env_profile.parse() {
return crate::backend::native::cpu_tuning::resolve_cpu_profile(profile);
}
eprintln!(
"Warning: Invalid SQLITEGRAPH_NATIVE_CPU_PROFILE '{}', using default profile",
env_profile
);
}
if let Some(profile) = self.cpu_profile {
return crate::backend::native::cpu_tuning::resolve_cpu_profile(profile);
}
CpuProfile::Generic
}
pub fn with_cpu_profile(mut self, profile: CpuProfile) -> Self {
self.cpu_profile = Some(profile);
self
}
pub fn with_parallel_recovery(mut self, degree: usize) -> Self {
self.max_parallel_transactions = degree;
self
}
pub fn with_checkpoint_strategy(mut self, strategy: CheckpointStrategy) -> Self {
self.checkpoint_strategy = Some(strategy);
self
}
pub fn with_transaction_checkpoint(mut self, threshold: u64) -> Self {
self.checkpoint_strategy = Some(CheckpointStrategy::TransactionCount(threshold));
self
}
pub fn with_size_checkpoint(mut self, threshold_bytes: u64) -> Self {
self.checkpoint_strategy = Some(CheckpointStrategy::SizeThreshold(threshold_bytes));
self
}
pub fn with_time_checkpoint(mut self, interval_secs: u64) -> Self {
self.checkpoint_strategy = Some(CheckpointStrategy::TimeInterval(Duration::from_secs(
interval_secs,
)));
self
}
}