mod defrag;
mod extents;
mod types;
pub use defrag::*;
pub use extents::*;
pub use types::*;
use alloc::string::String;
use alloc::vec::Vec;
use lazy_static::lazy_static;
use spin::Mutex;
lazy_static! {
static ref DEFRAG_TASKS: Mutex<Vec<DefragTask>> = Mutex::new(Vec::new());
}
pub struct Defrag;
impl Defrag {
pub fn fragmentation_score(dataset: &str, object_id: u64) -> Result<u8, DefragError> {
let extents = get_extents(dataset, object_id)?;
Ok(calculate_fragmentation(&extents))
}
pub fn defrag_file(
dataset: &str,
object_id: u64,
options: &DefragOptions,
) -> Result<DefragStats, DefragError> {
defrag_file(dataset, object_id, options)
}
pub fn defrag_dataset(
dataset: &str,
options: &DefragOptions,
) -> Result<DefragStats, DefragError> {
defrag_dataset(dataset, options)
}
pub fn start_background(dataset: &str, options: DefragOptions) -> Result<u64, DefragError> {
let task_id = start_background_defrag(dataset, options)?;
Ok(task_id)
}
pub fn cancel(task_id: u64) -> Result<(), DefragError> {
cancel_defrag_task(task_id)
}
pub fn progress(task_id: u64) -> Result<DefragProgress, DefragError> {
get_defrag_progress(task_id)
}
pub fn recommend(dataset: &str, object_id: u64) -> Result<DefragRecommendation, DefragError> {
let score = Self::fragmentation_score(dataset, object_id)?;
let extents = get_extents(dataset, object_id)?;
Ok(recommend_action(score, &extents))
}
}