use std::{future::Future, sync::Arc};
use wdev::Device;
use whlog::HybridLog;
use windex::HashIndex;
use crate::error::Result;
pub const TTL_VALUE_LEN: usize = wval::TTL_VAL_LEN;
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<u64>>>;
}
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);
}