use std::{future::Future, sync::Arc};
use wdev::Device;
use whlog::HybridLog;
use windex::HashIndex;
use crate::error::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CompactMetaInfo {
pub key_id: u64,
pub version: u64,
pub size: u64,
}
pub trait CompactSession<D: Device> {
type EpochGuard<'a>: Drop
where
Self: 'a;
fn enter_epoch(&self) -> Self::EpochGuard<'_>;
fn append_record(
&self,
key: &[u8],
val: &[u8],
expected_main_addr: u64,
is_tombstone: bool,
) -> impl Future<Output = Result<u64>>;
fn read_ttl_expiry(&self, ttl_key: &[u8]) -> impl Future<Output = Result<Option<i64>>>;
}
pub trait CompactStore {
type Device: Device;
type Session: CompactSession<Self::Device>;
fn new_session(self: &Arc<Self>) -> Result<Self::Session>;
fn hlog(&self) -> &HybridLog<Self::Device>;
fn index(&self) -> &HashIndex;
fn read_only_address(&self) -> u64;
fn begin_address(&self) -> u64;
fn shift_begin_address(&self, until: u64) -> impl Future<Output = Result<()>>;
fn is_read_cache_addr(&self, addr: u64) -> bool;
fn skip_read_cache(&self, addr: u64) -> u64;
fn enable_revivification(&self) -> bool;
fn reviv_put(&self, addr: u64, size: u32, read_only_addr: u64);
fn get_key_id_meta(&self, key_id: u64) -> Option<(u64, bool)>;
fn update_key_id_meta(&self, key_id: u64, version: u64, is_alive: bool);
fn remove_key_id_meta(&self, key_id: u64);
fn is_meta_key(&self, key: &[u8]) -> bool;
fn parse_meta_value(&self, val: &[u8]) -> Option<CompactMetaInfo>;
fn is_stale_subkey(&self, key: &[u8]) -> bool;
fn is_expired_or_orphan_record(
&self,
session: &Self::Session,
key: &[u8],
val: &[u8],
now: i64,
) -> impl Future<Output = bool>;
}