use std::{future::Future, sync::Arc};
use wdev::Device;
use super::garnet_database::GarnetDatabase;
use crate::storage::functions::functions_state::FunctionsState;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct HybridLogStats {
pub begin_address: u64,
pub read_only_address: u64,
pub head_address: u64,
pub tail_address: u64,
pub key_count: u64,
pub expire_count: u64,
}
pub trait IDatabaseManager<D: Device>: Send + Sync {
fn try_get_or_add_database(
&self,
db_id: i64,
) -> impl Future<Output = wkv::Result<(Arc<GarnetDatabase<D>>, bool)>>;
fn try_get_database(&self, db_id: i64) -> Option<Arc<GarnetDatabase<D>>>;
fn try_pause_checkpoints(&self, db_id: i64) -> bool;
fn resume_checkpoints(&self, db_id: i64);
fn recover_checkpoint_async(
&self,
replica_recover: bool,
recover_from_token: Option<u128>,
) -> impl Future<Output = wkv::Result<()>>;
fn take_checkpoint_async(
&self,
background: bool,
db_id: i64,
) -> impl Future<Output = wkv::Result<bool>>;
fn take_on_demand_checkpoint_async(
&self,
entry_ms: u64,
db_id: i64,
) -> impl Future<Output = wkv::Result<()>>;
fn task_checkpoint_based_on_aof_size_limit_async(
&self,
aof_size_limit: u64,
) -> impl Future<Output = wkv::Result<()>>;
fn commit_to_aof_async(&self, db_id: i64) -> wkv::Result<()>;
fn wait_for_commit_to_aof_async(&self, db_id: i64) -> wkv::Result<bool>;
fn recover_aof_async(&self) -> impl Future<Output = wkv::Result<u64>>;
fn replay_aof(&self, until: u64) -> impl Future<Output = wkv::Result<u64>>;
fn grow_indexes_if_needed_async(&self) -> wkv::Result<bool>;
fn execute_object_collection(&self, db_id: i64) -> impl Future<Output = wkv::Result<usize>>;
fn start_size_trackers(&self);
fn reset_revivification_stats(&self);
fn enqueue_commit(&self, db_id: i64, until: u64);
fn get_databases_snapshot(&self) -> Vec<Arc<GarnetDatabase<D>>>;
fn flush_database(&self, db_id: i64) -> impl Future<Output = wkv::Result<()>>;
fn flush_all_databases(&self) -> impl Future<Output = wkv::Result<()>>;
fn try_swap_databases(&self, db_id1: i64, db_id2: i64) -> impl Future<Output = bool>;
fn create_functions_state(&self, db_id: i64) -> FunctionsState;
fn collect_hybrid_log_stats(
&self,
) -> impl Future<Output = wkv::Result<Vec<(i64, HybridLogStats)>>>;
fn recover_vector_sets(&self, db_id: i64) -> wkv::Result<u64>;
}