#![cfg_attr(coverage_nightly, coverage(off))]
use super::*;
use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
use parking_lot::RwLock;
use sha2::{Digest, Sha256};
use std::io::{Read, Write};
use std::sync::Arc;
use tokio::fs::{create_dir_all, OpenOptions};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
pub struct SnapshotStore {
snapshots: Arc<RwLock<Vec<SnapshotMetadata>>>,
base_path: String,
config: SnapshotConfig,
}
#[derive(Clone)]
pub struct SnapshotConfig {
pub max_snapshots: usize,
pub compression_level: u32,
pub verify_on_write: bool,
pub verify_on_read: bool,
}
impl Default for SnapshotConfig {
fn default() -> Self {
Self {
max_snapshots: 10,
compression_level: 6,
verify_on_write: true,
verify_on_read: true,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SnapshotMetadata {
pub id: SnapshotId,
pub timestamp: SystemTime,
pub event_id: EventId,
pub checksum: String,
pub size_bytes: usize,
pub compressed_size: usize,
pub partition_key: Option<String>,
}
#[derive(Debug, Clone)]
pub struct SnapshotStats {
pub total_snapshots: usize,
pub total_size_bytes: usize,
pub total_compressed_bytes: usize,
pub compression_ratio: f64,
pub oldest_snapshot: Option<SnapshotMetadata>,
pub newest_snapshot: Option<SnapshotMetadata>,
}
#[derive(Debug, thiserror::Error)]
pub enum SnapshotError {
#[error("Snapshot not found: {0}")]
SnapshotNotFound(SnapshotId),
#[error("IO error: {0}")]
IoError(String),
#[error("Serialization error: {0}")]
SerializationError(String),
#[error("Compression error: {0}")]
CompressionError(String),
#[error("Checksum mismatch: expected {expected}, got {actual}")]
ChecksumMismatch { expected: String, actual: String },
}
include!("snapshot_store_persistence.rs");
include!("snapshot_store_retrieval.rs");
include!("snapshot_store_lifecycle.rs");
include!("snapshot_store_tests.rs");