use std::time::Duration;
use crate::crypto::CipherId;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RetainPolicy {
Count(u32),
Age(Duration),
Unbounded,
Disabled,
}
impl Default for RetainPolicy {
fn default() -> Self {
Self::Count(1024)
}
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct OpenOptions {
pub scratch_bytes: usize,
pub buffer_pool_pages: usize,
pub segment_cache_pages: usize,
pub mmap_view_scratch_bytes: usize,
pub commit_history_retain: RetainPolicy,
pub reader_stall_threshold_pages: u64,
pub observer_retry_count: u32,
pub metrics_enabled: bool,
pub anchor_budget: u64,
pub cipher: CipherId,
}
impl Default for OpenOptions {
fn default() -> Self {
Self {
scratch_bytes: 64 * 1024 * 1024,
buffer_pool_pages: 1024,
segment_cache_pages: 64,
mmap_view_scratch_bytes: 0,
commit_history_retain: RetainPolicy::default(),
reader_stall_threshold_pages: 100_000,
observer_retry_count: 3,
metrics_enabled: true,
anchor_budget: crate::crypto::nonce::DEFAULT_ANCHOR_BUDGET,
cipher: CipherId::Aes256Gcm,
}
}
}
impl OpenOptions {
#[must_use]
pub fn with_scratch_bytes(mut self, v: usize) -> Self {
self.scratch_bytes = v;
self
}
#[must_use]
pub fn with_buffer_pool_pages(mut self, v: usize) -> Self {
self.buffer_pool_pages = v;
self
}
#[must_use]
pub fn with_segment_cache_pages(mut self, v: usize) -> Self {
self.segment_cache_pages = v;
self
}
#[must_use]
pub fn with_mmap_view_scratch_bytes(mut self, v: usize) -> Self {
self.mmap_view_scratch_bytes = v;
self
}
#[must_use]
pub fn with_commit_history_retain(mut self, v: RetainPolicy) -> Self {
self.commit_history_retain = v;
self
}
#[must_use]
pub fn with_reader_stall_threshold_pages(mut self, v: u64) -> Self {
self.reader_stall_threshold_pages = v;
self
}
#[must_use]
pub fn with_observer_retry_count(mut self, v: u32) -> Self {
self.observer_retry_count = v;
self
}
#[must_use]
pub fn with_metrics_enabled(mut self, v: bool) -> Self {
self.metrics_enabled = v;
self
}
#[must_use]
pub fn with_anchor_budget(mut self, v: u64) -> Self {
self.anchor_budget = v;
self
}
#[must_use]
pub fn with_cipher(mut self, v: CipherId) -> Self {
self.cipher = v;
self
}
}