solana/runtime/src/tiered_storage.rs

70 lines
1.7 KiB
Rust
Raw Normal View History

#![allow(dead_code)]
pub mod byte_block;
pub mod error;
pub mod file;
pub mod footer;
pub mod hot;
pub mod index;
pub mod meta;
pub mod mmap_utils;
pub mod readable;
use {
error::TieredStorageError,
footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat},
index::AccountIndexFormat,
std::path::{Path, PathBuf},
};
pub type TieredStorageResult<T> = Result<T, TieredStorageError>;
/// The struct that defines the formats of all building blocks of a
/// TieredStorage.
#[derive(Clone, Debug)]
pub struct TieredStorageFormat {
pub meta_entry_size: usize,
pub account_meta_format: AccountMetaFormat,
pub owners_block_format: OwnersBlockFormat,
pub account_index_format: AccountIndexFormat,
pub account_block_format: AccountBlockFormat,
}
#[derive(Debug)]
pub struct TieredStorage {
format: Option<TieredStorageFormat>,
path: PathBuf,
}
impl TieredStorage {
/// Creates a new writable instance of TieredStorage based on the
/// specified path and TieredStorageFormat.
///
/// Note that the actual file will not be created until append_accounts
/// is called.
pub fn new_writable(path: impl Into<PathBuf>, format: TieredStorageFormat) -> Self {
Self {
format: Some(format),
path: path.into(),
}
}
/// Returns the path to this TieredStorage.
pub fn path(&self) -> &Path {
self.path.as_path()
}
}
#[cfg(test)]
mod tests {
use {super::*, hot::HOT_FORMAT};
#[test]
fn test_new_writable() {
let path = PathBuf::default();
let ts = TieredStorage::new_writable(&path, HOT_FORMAT.clone());
assert_eq!(ts.path(), path);
}
}