use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReadPoolConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_pool_size")]
pub pool_size: usize,
#[serde(default = "default_acquire_timeout")]
pub acquire_timeout_ms: u64,
}
impl Default for ReadPoolConfig {
fn default() -> Self {
Self {
enabled: false,
pool_size: default_pool_size(),
acquire_timeout_ms: default_acquire_timeout(),
}
}
}
impl ReadPoolConfig {
pub fn enabled(pool_size: usize) -> Self {
Self {
enabled: true,
pool_size,
acquire_timeout_ms: default_acquire_timeout(),
}
}
pub fn with_timeout(mut self, timeout_ms: u64) -> Self {
self.acquire_timeout_ms = timeout_ms;
self
}
}
fn default_pool_size() -> usize {
4
}
fn default_acquire_timeout() -> u64 {
5000
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CanonicalConfig {
pub path: PathBuf,
#[serde(default = "default_map_size")]
pub map_size: usize,
#[serde(default)]
pub sync_mode: SyncMode,
#[serde(default = "default_stripe_count")]
pub stripe_count: usize,
#[serde(default = "default_max_readers")]
pub max_readers: u32,
#[serde(default = "default_true")]
pub preflight_read_only: bool,
#[serde(default = "default_chunk_size")]
pub state_iter_chunk_size: usize,
#[serde(default = "default_true")]
pub preflight_cache_enabled: bool,
#[serde(default = "default_preflight_cache_size")]
pub preflight_cache_size: usize,
#[serde(default = "default_preflight_cache_ttl")]
pub preflight_cache_ttl_secs: u64,
#[serde(default)]
pub read_pool: ReadPoolConfig,
#[serde(default = "default_lock_timeout")]
pub lock_timeout_ms: u64,
#[serde(default = "default_event_max_size")]
pub event_max_size_bytes: usize,
#[serde(default = "default_event_batch_max_bytes")]
pub event_batch_max_bytes: usize,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
pub enum SyncMode {
Full,
#[default]
NoMetaSync,
NoSync,
}
fn default_map_size() -> usize {
10 * 1024 * 1024 * 1024 }
fn default_stripe_count() -> usize {
256
}
fn default_max_readers() -> u32 {
126
}
fn default_true() -> bool {
true
}
fn default_chunk_size() -> usize {
1000
}
fn default_preflight_cache_size() -> usize {
10_000
}
fn default_preflight_cache_ttl() -> u64 {
60
}
fn default_lock_timeout() -> u64 {
5000
}
fn default_event_max_size() -> usize {
4 * 1024 * 1024
}
fn default_event_batch_max_bytes() -> usize {
64 * 1024 * 1024
}
impl CanonicalConfig {
pub fn new(path: PathBuf) -> Self {
Self {
path,
map_size: default_map_size(),
sync_mode: SyncMode::default(),
stripe_count: default_stripe_count(),
max_readers: default_max_readers(),
preflight_read_only: default_true(),
state_iter_chunk_size: default_chunk_size(),
preflight_cache_enabled: default_true(),
preflight_cache_size: default_preflight_cache_size(),
preflight_cache_ttl_secs: default_preflight_cache_ttl(),
read_pool: ReadPoolConfig::default(),
lock_timeout_ms: default_lock_timeout(),
event_max_size_bytes: default_event_max_size(),
event_batch_max_bytes: default_event_batch_max_bytes(),
}
}
pub fn with_map_size(mut self, map_size: usize) -> Self {
self.map_size = map_size;
self
}
pub fn with_sync_mode(mut self, sync_mode: SyncMode) -> Self {
self.sync_mode = sync_mode;
self
}
pub fn with_stripe_count(mut self, stripe_count: usize) -> Self {
self.stripe_count = stripe_count;
self
}
pub fn with_preflight_cache(mut self, enabled: bool) -> Self {
self.preflight_cache_enabled = enabled;
self
}
pub fn with_preflight_cache_size(mut self, size: usize) -> Self {
self.preflight_cache_size = size;
self
}
pub fn with_preflight_cache_ttl(mut self, ttl_secs: u64) -> Self {
self.preflight_cache_ttl_secs = ttl_secs;
self
}
pub fn with_read_pool(mut self, config: ReadPoolConfig) -> Self {
self.read_pool = config;
self
}
pub fn with_read_pool_size(mut self, pool_size: usize) -> Self {
self.read_pool = ReadPoolConfig::enabled(pool_size);
self
}
pub fn with_lock_timeout(mut self, timeout_ms: u64) -> Self {
self.lock_timeout_ms = timeout_ms;
self
}
pub fn with_event_max_size(mut self, size_bytes: usize) -> Self {
self.event_max_size_bytes = size_bytes;
self
}
pub fn with_event_batch_max_bytes(mut self, size_bytes: usize) -> Self {
self.event_batch_max_bytes = size_bytes;
self
}
}