use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type")]
pub enum StorageStrategy {
PureSharding,
Replication { factor: u8 },
ErasureCoding { k: u8, m: u8 },
}
impl Default for StorageStrategy {
fn default() -> Self {
Self::Replication { factor: 3 }
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TablePolicy {
pub hot_ttl_days: Option<u32>,
pub hot_strategy: StorageStrategy,
pub warm_ttl_days: Option<u32>,
pub warm_strategy: StorageStrategy,
pub cold_ttl_days: Option<u32>,
pub cold_strategy: StorageStrategy,
}
impl Default for TablePolicy {
fn default() -> Self {
Self {
hot_ttl_days: Some(30),
hot_strategy: StorageStrategy::Replication { factor: 3 },
warm_ttl_days: Some(180),
warm_strategy: StorageStrategy::PureSharding,
cold_ttl_days: None,
cold_strategy: StorageStrategy::ErasureCoding { k: 4, m: 2 },
}
}
}
impl TablePolicy {
pub fn to_json(&self) -> Result<String, String> {
serde_json::to_string(self).map_err(|e| e.to_string())
}
pub fn from_json(json: &str) -> Result<Self, String> {
serde_json::from_str(json).map_err(|e| e.to_string())
}
}