use std::io::{Read, Write};
use anyhow::Result;
use metrale_cache::kv_spill::KvSpillManager;
use metrale_scheduler::SpillIo;
pub struct FileSpill(parking_lot::Mutex<KvSpillManager>);
impl FileSpill {
pub fn new(manager: KvSpillManager) -> Self {
Self(parking_lot::Mutex::new(manager))
}
}
impl SpillIo for FileSpill {
fn create(&self) -> Result<(u64, Box<dyn Write + Send>)> {
let (id, writer) = self.0.lock().create_file()?;
Ok((id, Box::new(writer)))
}
fn open(&self, id: u64) -> Result<Box<dyn Read + Send>> {
Ok(Box::new(self.0.lock().open_file(id)?))
}
fn remove(&self, id: u64) -> Result<()> {
self.0.lock().remove_file(id)
}
fn record_usage(&self, id: u64) {
self.0.lock().record_usage(id);
}
}