iroh_blobs/store/fs/
options.rsuse std::{
path::{Path, PathBuf},
time::Duration,
};
pub use super::gc::{GcConfig, ProtectCb, ProtectOutcome};
use super::{meta::raw_outboard_size, temp_name};
use crate::Hash;
#[derive(Debug, Clone)]
pub struct PathOptions {
pub data_path: PathBuf,
pub temp_path: PathBuf,
}
impl PathOptions {
pub fn new(root: &Path) -> Self {
Self {
data_path: root.join("data"),
temp_path: root.join("temp"),
}
}
pub fn data_path(&self, hash: &Hash) -> PathBuf {
self.data_path.join(format!("{}.data", hash.to_hex()))
}
pub fn outboard_path(&self, hash: &Hash) -> PathBuf {
self.data_path.join(format!("{}.obao4", hash.to_hex()))
}
pub fn sizes_path(&self, hash: &Hash) -> PathBuf {
self.data_path.join(format!("{}.sizes4", hash.to_hex()))
}
pub fn bitfield_path(&self, hash: &Hash) -> PathBuf {
self.data_path.join(format!("{}.bitfield", hash.to_hex()))
}
pub fn temp_file_name(&self) -> PathBuf {
self.temp_path.join(temp_name())
}
}
#[derive(Debug, Clone)]
pub struct InlineOptions {
pub max_data_inlined: u64,
pub max_outboard_inlined: u64,
}
impl InlineOptions {
pub const NO_INLINE: Self = Self {
max_data_inlined: 0,
max_outboard_inlined: 0,
};
pub const ALWAYS_INLINE: Self = Self {
max_data_inlined: u64::MAX,
max_outboard_inlined: u64::MAX,
};
}
impl Default for InlineOptions {
fn default() -> Self {
Self {
max_data_inlined: 1024 * 16,
max_outboard_inlined: 1024 * 16,
}
}
}
#[derive(Debug, Clone)]
pub struct BatchOptions {
pub max_read_batch: usize,
pub max_read_duration: Duration,
pub max_write_batch: usize,
pub max_write_duration: Duration,
}
impl Default for BatchOptions {
fn default() -> Self {
Self {
max_read_batch: 10000,
max_read_duration: Duration::from_secs(1),
max_write_batch: 1000,
max_write_duration: Duration::from_millis(500),
}
}
}
#[derive(Debug, Clone)]
pub struct Options {
pub path: PathOptions,
pub inline: InlineOptions,
pub batch: BatchOptions,
pub gc: Option<GcConfig>,
}
impl Options {
pub fn new(root: &Path) -> Self {
Self {
path: PathOptions::new(root),
inline: InlineOptions::default(),
batch: BatchOptions::default(),
gc: None,
}
}
pub fn is_inlined_data(&self, data_size: u64) -> bool {
data_size <= self.inline.max_data_inlined
}
pub fn is_inlined_outboard(&self, outboard_size: u64) -> bool {
outboard_size <= self.inline.max_outboard_inlined
}
pub fn is_inlined_all(&self, data_size: u64) -> bool {
let outboard_size = raw_outboard_size(data_size);
self.is_inlined_data(data_size) && self.is_inlined_outboard(outboard_size)
}
}