dbx_core/engine/
policy.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5#[serde(tag = "type")]
6pub enum StorageStrategy {
7 PureSharding,
9 Replication { factor: u8 },
11 ErasureCoding { k: u8, m: u8 },
13}
14
15impl Default for StorageStrategy {
16 fn default() -> Self {
17 Self::Replication { factor: 3 }
18 }
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
23pub struct TablePolicy {
24 pub hot_ttl_days: Option<u32>,
26 pub hot_strategy: StorageStrategy,
27
28 pub warm_ttl_days: Option<u32>,
30 pub warm_strategy: StorageStrategy,
31
32 pub cold_ttl_days: Option<u32>,
34 pub cold_strategy: StorageStrategy,
35}
36
37impl Default for TablePolicy {
38 fn default() -> Self {
39 Self {
40 hot_ttl_days: Some(30),
41 hot_strategy: StorageStrategy::Replication { factor: 3 },
42 warm_ttl_days: Some(180),
43 warm_strategy: StorageStrategy::PureSharding,
44 cold_ttl_days: None,
45 cold_strategy: StorageStrategy::ErasureCoding { k: 4, m: 2 },
46 }
47 }
48}
49
50impl TablePolicy {
51 pub fn to_json(&self) -> Result<String, String> {
53 serde_json::to_string(self).map_err(|e| e.to_string())
54 }
55
56 pub fn from_json(json: &str) -> Result<Self, String> {
58 serde_json::from_str(json).map_err(|e| e.to_string())
59 }
60}