use crate::manifest::StoredArchive;
use crate::repository::ChunkID;
use crate::repository::ChunkSettings;
use crate::repository::EncryptedKey;
use anyhow::Result;
use async_trait::async_trait;
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
pub mod common;
pub mod mem;
pub mod multifile;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SegmentDescriptor {
pub segment_id: u64,
pub start: u64,
}
#[async_trait]
pub trait Manifest: Send + Sync + Clone + std::fmt::Debug {
type Iterator: Iterator<Item = StoredArchive>;
async fn last_modification(&mut self) -> DateTime<FixedOffset>;
async fn chunk_settings(&mut self) -> ChunkSettings;
async fn archive_iterator(&mut self) -> Self::Iterator;
async fn write_chunk_settings(&mut self, settings: ChunkSettings);
async fn write_archive(&mut self, archive: StoredArchive);
async fn touch(&mut self);
}
#[async_trait]
pub trait Index: Send + Sync + Clone + std::fmt::Debug {
async fn lookup_chunk(&mut self, id: ChunkID) -> Option<SegmentDescriptor>;
async fn set_chunk(&mut self, id: ChunkID, location: SegmentDescriptor) -> Result<()>;
async fn commit_index(&mut self) -> Result<()>;
async fn count_chunk(&mut self) -> usize;
}
#[async_trait]
pub trait Backend: 'static + Send + Sync + Clone + std::fmt::Debug {
type Manifest: Manifest + 'static;
type Index: Index + 'static;
fn get_index(&self) -> Self::Index;
async fn write_key(&self, key: &EncryptedKey) -> Result<()>;
async fn read_key(&self) -> Result<EncryptedKey>;
fn get_manifest(&self) -> Self::Manifest;
async fn read_chunk(&mut self, location: SegmentDescriptor) -> Result<Vec<u8>>;
async fn write_chunk(&mut self, chunk: Vec<u8>, id: ChunkID) -> Result<SegmentDescriptor>;
}
#[derive(Copy, PartialEq, Eq, Clone, Serialize, Deserialize, Debug)]
pub enum TransactionType {
Insert,
Delete,
}