use crate::error::{CoreError, Result};
use crate::limits::GC_MIN_GRACE_WINDOW_MS;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GcConfig {
pub grace_window_ms: u64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub max_objects: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
}
impl Default for GcConfig {
fn default() -> Self {
Self {
grace_window_ms: 60 * 60 * 1000,
max_objects: None,
cursor: None,
}
}
}
impl GcConfig {
pub(super) fn validate(&self) -> Result<()> {
if self.grace_window_ms < GC_MIN_GRACE_WINDOW_MS {
return Err(CoreError::InvalidGcConfig(format!(
"grace_window_ms {} is below the derived safety minimum {}",
self.grace_window_ms, GC_MIN_GRACE_WINDOW_MS
)));
}
if self.max_objects == Some(0) {
return Err(CoreError::InvalidGcConfig(
"max_objects must be greater than zero".to_owned(),
));
}
Ok(())
}
}