use rand::Rng;
#[derive(Debug, Clone)]
pub struct ShadowValidationConfig {
pub enabled: bool,
pub sample_rate: f64,
}
impl Default for ShadowValidationConfig {
fn default() -> Self {
Self {
enabled: false,
sample_rate: 0.1, }
}
}
impl ShadowValidationConfig {
pub fn enabled() -> Self {
Self {
enabled: true,
sample_rate: 1.0,
}
}
pub fn with_sample_rate(rate: f64) -> Self {
Self {
enabled: true,
sample_rate: rate.clamp(0.0, 1.0),
}
}
}
#[derive(Debug, Clone)]
pub struct ShadowValidationResult {
pub passed: bool,
pub index_type: String,
pub expected: ShadowMetrics,
pub actual: Option<ShadowMetrics>,
pub discrepancies: Vec<String>,
}
#[derive(Debug, Clone, Default)]
pub struct ShadowMetrics {
pub item_count: usize,
pub tombstone_count: usize,
pub snapshot_size: usize,
}
pub(crate) fn should_sample(rate: f64) -> bool {
if rate >= 1.0 {
return true;
}
if rate <= 0.0 {
return false;
}
rand::thread_rng().gen::<f64>() < rate
}
pub(crate) fn log_validation_result(result: &ShadowValidationResult) {
if !result.passed {
tracing::warn!(
index_type = %result.index_type,
discrepancies = ?result.discrepancies,
"Shadow validation failed"
);
}
}