use super::{
config_kind::ConfigKind, config_time_unit::ConfigTimeUnit,
log_compaction_type::LogCompactionType, runtime_server_config::RuntimeServerConfig,
runtime_server_options::RuntimeServerOptions,
};
pub trait ConfigUpdateOwner: Send + Sync {
fn reconcile_commit_task(&self);
fn reconcile_object_collect_task(&self);
fn reconcile_expired_key_deletion_task(&self);
fn apply_aof_sync_max_lag_bytes(&self, max_lag_bytes: i64);
}
pub type ConfigUpdateAction =
fn(&RuntimeServerConfig, old_value: i64, new_value: i64) -> Result<(), super::error::ConfigError>;
#[derive(Clone)]
pub struct ConfigMeta {
pub name: &'static str,
pub kind: ConfigKind,
pub min: i64,
pub max: i64,
pub enum_type: Option<EnumMeta>,
pub is_runtime: bool,
pub read_only: bool,
pub time_unit: ConfigTimeUnit,
pub read_only_formatter: Option<fn(&RuntimeServerOptions) -> String>,
pub update_action: Option<ConfigUpdateAction>,
}
impl ConfigMeta {
pub const EMPTY: Self = Self {
name: "",
kind: super::config_kind::ConfigKind::NONE,
min: 0,
max: 0,
enum_type: None,
is_runtime: false,
read_only: false,
time_unit: ConfigTimeUnit::None,
read_only_formatter: None,
update_action: None,
};
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EnumMeta {
LogCompactionType,
}
impl EnumMeta {
pub fn try_parse_to_long(self, value: &str) -> Option<i64> {
match self {
Self::LogCompactionType => LogCompactionType::try_parse(value).map(|v| i64::from(v as u8)),
}
}
pub fn name_of(self, raw: i64) -> Option<&'static str> {
match self {
Self::LogCompactionType => LogCompactionType::from_raw(raw).map(LogCompactionType::as_name),
}
}
}